What’s the difference between Object.entries
and Object.keys
? In which case should I use one or the other one?
Advertisement
Answer
Object.keys
returns only the own property names and works for ES5.
Object.entries
returns an array of arrays with key and value and works from ES6.
If you need only keys or like to filter the keys, then take Object.keys
, otherwise Object.entries
.