What are Object.entries/keys/values?
The Object.keys(), Object.values(), and Object.entries() methods are a standard and convenient set of tools for transforming objects into arrays and subsequently iterating over them. Each of these static methods solves its own specific task of extracting data from a key-value structure.
The Object.keys() method takes an object as an argument and returns an array of strings containing all the own enumerable property names of that object. The Object.values() method, conversely, returns an array of values corresponding to those keys. The Object.entries() method combines both approaches, returning a two-dimensional array of pairs where each element is an array of the form [key, value], which is ideal for loops like for...of or passing into array methods.
An important feature of all three methods is that they work exclusively with the object's own enumerable properties. This means that properties inherited through the prototype chain, as well as properties with the enumerable flag set to false, will be automatically ignored and will not be included in the resulting arrays.
For the reverse transformation in JavaScript, the Object.fromEntries() method is provided. It performs the opposite operation, taking an array of [key, value] pairs (or any other iterable object with the same format) and assembling them into a fully-fledged object. This trio of methods, combined with array methods like map, filter, and reduce, forms a powerful pipeline for the declarative processing and transformation of data of any complexity.