Loading topic
Object.keys, Object.values, and Object.entries don't return everything an object can reach. They return a filtered set: the object's own, enumerable, string-keyed properties. This chapter explain5 min readfor...of loop. It also builds on the previous chapter's idea of own enumerable string-keyed properties: the properties defined directly on an object, visible to 5 min readObject.values is the tool for these jobs.5 min readObject.keys to get an object's keys and Object.values to get its values. Many loops need both at once: a label and its count, a setting name and its value, a user ID and its record. Object.entries returns both together, as pairs.5 min readconst and let, template literals, arrays and for...of, and what Object.entries returns, which the previous chapter covered: an array of [key, value] pairs. Here the focus is the loop head itself. It covers how the [key, value] pattern unpacks each pair, what4 min readObject.keys, Object.values, and Object.entries return ordinary arrays. That means every array method you already know works on an object's data once you have converted it. This chapter covers how forEach, map, filter, reduce, and their relatives behave on keys and entries, and where pe5 min readObject.keys existed: the for...in statement. Both still work, and on a plain object literal they often print the same keys. They answer different questions, though. Object.keys asks "what keys does this object itself have?" The `fo6 min readObject.keys, Object.values, or Object.entries, the properties arrive in a fixed, predictable order. That order is not always the order you typed them in. Code that renders a list, builds a report, or compares two objects often depends on this order without any5 min readObject.entries, array destructuring in arrow-function parameters, and the array methods map, filter, and reduce. The earlier chapters covered how to take an object apart into [key, value] pairs. This chapter goes the other way: it shows how to put pairs back t5 min readObject.keys, Object.values, and Object.entries work, and that you're comfortable with for...of, destructuring, and basic array methods. Earlier chapters described these methods as returning an object's own enumerable string-keyed properties. This c6 min readObject.keys, Object.values, and Object.entries on plain object literals. Real code is messier than that. A function receives null because an API response had no data. A helper meant for objects gets an array, a string, or a Map. This chapter covers what the three meth5 min readObject.keys, Object.entries, destructuring in for...of, for...in, and Object.fromEntries, all covered earlier in this tutorial. It answers one practical question: what happens when the loop body changes the object you are looping over?5 min read