Object keys and values to array
suggest changeconst object = {
key1: 10,
key2: 3,
key3: 40,
key4: 20
};
const array = [];
for(const people in object) {
array.push([people, object[people]]);
}
for...in also visits enumerable properties inherited from the prototype. For this object’s own keys, in insertion order, array is:
[
["key1", 10],
["key2", 3],
["key3", 40],
["key4", 20]
]
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents