-
-
Save MonaTem/10ed10d8e68032f0c3950b4a72ee6d39 to your computer and use it in GitHub Desktop.
Reduce example #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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