Last active
September 11, 2019 21:04
-
-
Save blurpesec/8aac8afd791ac7ea457c6e5acf2ec62a to your computer and use it in GitHub Desktop.
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
// basically after you get the mapped array, you can just create a new object like this: | |
const arrayOfObjects = [ | |
{ | |
'name': 'one', | |
'foo': 1, | |
'foobar': 2, | |
'foobarbaz': 3 | |
}, | |
{ | |
'name': 'two', | |
'foo': 1, | |
'foobar': 2, | |
'foobarbaz': 3 | |
} | |
] | |
const objectOfObjects = {}; | |
arrayOfObjects.forEach(object => { | |
objectOfObjects[object.name] = object; | |
}) | |
console.log(objectOfObjects); | |
/* This will be logged out: | |
{ | |
'one': { | |
'name': 'one', | |
'foo': 1, | |
'foobar': 2, | |
'foobarbaz': 3 | |
}, | |
'two': { | |
'name': 'two', | |
'foo': 1, | |
'foobar': 2, | |
'foobarbaz': 3 | |
} | |
} */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment