Get key-value pairs with Object.entries()
const user = { name: "Ada", age: 36 };
console.log(Object.entries(user));
// [["name", "Ada"], ["age", 36]]
Each inner array holds a key and its value, which is perfect for looping or mapping over an object.
Get just the keys or just the values
const user = { name: "Ada", age: 36 };
console.log(Object.keys(user)); // ["name", "age"]
console.log(Object.values(user)); // ["Ada", 36]
Loop over an object as an array
const prices = { apple: 2, pear: 3 };
Object.entries(prices).forEach(([item, price]) => {
console.log(item + ": " + price);
});
Destructuring [item, price] unpacks each pair, so you can read both the key and the value cleanly.
Which method should you use?
- Object.entries() — when you need both keys and values.
- Object.keys() — when you only need the property names.
- Object.values() — when you only need the values.
- Common mistake: trying to call array methods like
mapdirectly on the object — convert it first.
Frequently asked questions
How do I turn the array back into an object?
Use Object.fromEntries(pairs), which is the exact reverse of Object.entries().
Are the keys always in a predictable order?
For string keys, yes — they follow insertion order. Integer-like keys are listed first in ascending numeric order.
Want to understand objects deeply? Our free JavaScript course covers them with hands-on examples.