diff --git a/README.md b/README.md index 2cd816916..b449e0318 100644 --- a/README.md +++ b/README.md @@ -447,6 +447,8 @@ const objectFromPairs = arr => arr.reduce((a, v) => (a[v[0]] = v[1], a), {}); ### Object to key-value pairs +Use `Object.keys()` and `Array.map()` to iterate over the object's keys and produce an array with key-value pairs. + ```js const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]); // objectToPairs({a: 1, b: 2}) -> [['a',1],['b',2]]) diff --git a/snippets/object-to-key-value-pairs.md b/snippets/object-to-key-value-pairs.md index 78fd63811..fb639e432 100644 --- a/snippets/object-to-key-value-pairs.md +++ b/snippets/object-to-key-value-pairs.md @@ -1,5 +1,7 @@ ### Object to key-value pairs +Use `Object.keys()` and `Array.map()` to iterate over the object's keys and produce an array with key-value pairs. + ```js const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]); // objectToPairs({a: 1, b: 2}) -> [['a',1],['b',2]])