Skip to content

Instantly share code, notes, and snippets.

@blurpesec
Last active September 11, 2019 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blurpesec/8aac8afd791ac7ea457c6e5acf2ec62a to your computer and use it in GitHub Desktop.
Save blurpesec/8aac8afd791ac7ea457c6e5acf2ec62a to your computer and use it in GitHub Desktop.
// 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