With lodash
:
const items = [
{ key: 'foo', value: 'bar' },
{ key: 'hello', value: 'world' }
];
const map = _.fromPairs(items.map(item => [item.key, item.val]));
// OR: if you want to index the whole item by key:
// const map = _.fromPairs(items.map(item => [item.key, item]));
The lodash fromPairs
function reminds me about zip function in Python
Link to lodash