I'm working with an array that looks like this:
const inventory = [
{ fruit: 'apple', quality: 'good', quantity: 10 },
{ fruit: 'banana', quality: 'average', quantity: 5 },
{ fruit: 'orange', quality: 'excellent', quantity: 12 },
];
If I want to retrieve information about the "banana" entry, I currently use:
inventory.find(item => item.fruit === 'banana')
However, I'd prefer to access it associatively, like this:
inventory.banana.quantity
To achieve this format, I need to transform my array into an object. I am looking for a simple ES6 solution or possibly utilizing Lodash. Any suggestions?