From 3da9f8e40dd528055fdb4a1762eb36bd7bbe2a71 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Mon, 10 Sep 2018 05:32:36 +0000 Subject: [PATCH] Travis build: 425 --- README.md | 2 +- docs/object.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b32ab8e08..b13302e49 100644 --- a/README.md +++ b/README.md @@ -7084,7 +7084,7 @@ Creates an object from the given key-value pairs. Use `Array.reduce()` to create and combine key-value pairs. ```js -const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), {}); +const objectFromPairs = arr => arr.reduce((a, [key, val]) => ((a[key] = val), a), {}); ```
diff --git a/docs/object.html b/docs/object.html index f3d2097ba..addef240f 100644 --- a/docs/object.html +++ b/docs/object.html @@ -278,7 +278,7 @@ Foo.prototype: 5, parent_id: 4 } ]; const nestedComments = nest(comments); // [{ id: 1, parent_id: null, children: [...] }] -

objectFromPairs

Creates an object from the given key-value pairs.

Use Array.reduce() to create and combine key-value pairs.

const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), {});
+

objectFromPairs

Creates an object from the given key-value pairs.

Use Array.reduce() to create and combine key-value pairs.

const objectFromPairs = arr => arr.reduce((a, [key, val]) => ((a[key] = val), a), {});
 
objectFromPairs([['a', 1], ['b', 2]]); // {a: 1, b: 2}
 

objectToPairs

Creates an array of key-value pair arrays from an object.

Use Object.keys() and Array.map() to iterate over the object's keys and produce an array with key-value pairs.

const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]);
 
objectToPairs({ a: 1, b: 2 }); // [['a',1],['b',2]]