Iterating entries with Object.entries

suggest change

Object.entries() has been standard since ES2017. It returns an array of an object's own enumerable string keys and their values. It skips symbols and inherited properties. Keys that look like array indexes are listed first, in numeric order. The others follow in insertion order. It is an array, not an iterator like Array.prototype.entries().

const obj = {
    one: 1,
    two: 2,
    three: 3
};

Object.entries(obj);

Results in:

[
    ["one", 1],
    ["two", 2],
    ["three", 3]
]

That array is a useful way to iterate the pairs:

for (const [key, value] of Object.entries(obj)) {
    console.log(key); // "one", "two" and "three"
    console.log(value); // 1, 2 and 3
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents