Skip to content

Instantly share code, notes, and snippets.

@maulberto3
Last active July 12, 2018 04:01
Show Gist options
  • Save maulberto3/f3d6a64137b742156df36707db8b9494 to your computer and use it in GitHub Desktop.
Save maulberto3/f3d6a64137b742156df36707db8b9494 to your computer and use it in GitHub Desktop.
Reduce example #3
const arr = [["dog", 1], ["cat", 2], ["bear", 3]];
const func1 = ([key, v1]) => ({ [key]: v1 }); // creates an object out of the array
const obj2 = arr.map(func1)
console.log(JSON.stringify(obj2, null, 2)); // Prints [ { "dog": 1 }, { "cat": 2 }, { "bear": 3 } ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment