Skip to content

Instantly share code, notes, and snippets.

@FBosler
Last active August 20, 2020 21:02
Show Gist options
  • Save FBosler/aac3f39012a06a222e6712e5d0a41b9b to your computer and use it in GitHub Desktop.
Save FBosler/aac3f39012a06a222e6712e5d0a41b9b to your computer and use it in GitHub Desktop.
const sample_data = [{'_id': 'cc7b7a9d8b9642299e3657af08dc0e2a',
'name': 'zCKVZkcKvB',
'net_worth': 45000},
{'_id': '0ec97c94bc654b3a84f47591169f75eb',
'name': 'LxfVwDeufE',
'net_worth': 39000},
{'_id': '1e2ea336022142c3be60ba174433c3d7',
'name': 'ZjhiifKLCp',
'net_worth': 68000},
{'_id': '37ba69d4661744cdb4e6d2f3b66734ec',
'name': 'WaVDrBSTxA',
'net_worth': 37000},
{'_id': 'aca980129610454597ae90296cc984ef',
'name': 'QRsgCCLGEa',
'net_worth': 83000},
{'_id': 'addb82ec89244e869393708c1ab042bd',
'name': 'fVtVcfatej',
'net_worth': 33000},
{'_id': '99ca22ac0df44c8e80a75ee242a4fa8e',
'name': 'SGRRVqAyWf',
'net_worth': 10000},
{'_id': '832e3fbe3986424eb1a831d26a67e5d4',
'name': 'dZZmNdQZlK',
'net_worth': 93000},
{'_id': '799191fd49034e3b8795bd463b69cadd',
'name': 'URCMuxXsll',
'net_worth': 51000},
{'_id': '526d1a87190d4fcabee4e79e43616d69',
'name': 'mUPevdfCEY',
'net_worth': 19000}]
const result = sample_data.reduce((map, obj) => {
map[obj._id] = obj;
return map;
}, {});
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment