Skip to content

Commit 8db6519

Browse files
committed
minor fixes
1 parent 7725acc commit 8db6519

File tree

1 file changed

+5
-4
lines changed
  • 1-js/05-data-types/09-keys-values-entries

1 file changed

+5
-4
lines changed

1-js/05-data-types/09-keys-values-entries/article.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Objects lack many methods that exist for arrays, e.g. `map`, `filter` and others
7777
If we'd like to apply them, then we can use `Object.entries` followed by `Object.fromEntries`:
7878

7979
1. Use `Object.entries(obj)` to get an array of key/value pairs from `obj`.
80-
2. Use array methods on that array, e.g. `map`.
80+
2. Use array methods on that array, e.g. `map`, to transform key/value pairs.
8181
3. Use `Object.fromEntries(array)` on the resulting array to turn it back into an object.
8282

8383
For example, we have an object with prices, and would like to double them:
@@ -91,12 +91,13 @@ let prices = {
9191

9292
*!*
9393
let doublePrices = Object.fromEntries(
94-
// convert to array, map, and then fromEntries gives back the object
95-
Object.entries(prices).map(([key, value]) => [key, value * 2])
94+
// convert prices to array, map key/value pairs into another pair
95+
// and then fromEntries gives back the object
96+
Object.entries(prices).map(entry => [entry[0], entry[1] * 2])
9697
);
9798
*/!*
9899

99100
alert(doublePrices.meat); // 8
100101
```
101102

102-
It may look difficult at first sight, but becomes easy to understand after you use it once or twice. We can make powerful chains of transforms this way.
103+
It may look difficult at first sight, but becomes easy to understand after you use it once or twice. We can make powerful chains of transforms this way.

0 commit comments

Comments
 (0)