Last active
November 30, 2016 04:57
-
-
Save KinoAR/ac9e6b4502ca916fa212bbfa7f770203 to your computer and use it in GitHub Desktop.
Array.Reduce JavaScript Tutorial Code
This file contains 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
'use strict' | |
//Object Reduce | |
let names = ['Ray', 'Hiro', 'Ross']; | |
let obj = names.reduce(function(finalObj, name, index){ | |
//Create new property on object based on index (1, 2, 3) and assign name to it | |
index+=1; | |
finalObj[index] = name; | |
console.log(finalObj[index]); | |
return finalObj; //return the object for the next iteration | |
}, {}); | |
console.log(obj);// {1: 'Ray', 2: 'Hiro', 3: 'Ross'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment