1 points · by thinkloop · 8y ago · 4 comments
Object.keys(key => {})
// values
Object.values(value => {})
// * * entries * *
Object.entries(weirdArray => { key = weirdArray[0]; value = weirdArray[1]; })
Why not:
Object.entries(entry => { key = entry.key; value = entry.value; })
Or:
Object.entries((key, value) => {})
So why use an array of arrays like this? Most likely it's symmetry and composition. The inverse of this operation is to build an object from a list of key+value pairs, and the most natural way to represent that is with an array of two-element arrays. A similar pair of operations that uses an array of objects which carry more information is Object.getOwnPropertyDescriptors()/Object.create().
Object.entries(([k, v]) => { })
Object.entries({}).forEach(([k, v]) => { })