I have this array:
const demo = [
{ key: 'apple', a: 'b', c: 1 },
{ key: 'banana', a: 'f', c: 3 },
{ key: 'orange', a: 'j', c: 8 },
];
I can get info about “banana” by using:
demo.find(item => item.key === 'banana')
Instead I would like to have this associative and access like this:
demo.banana.c
So I need to somehow get this:
const demo = {
'apple': { key: 'apple', a: 'b', c: 1 },
'banana': { key: 'banana', a: 'f', c: 3 },
'orange': { key: 'orange', a: 'j', c: 8 },
};
Or without “key” inside, it does not matter.
What would be simplest solution? Some simple (maybe one-line) approach with ES6? If not, Lodash instead?