//Organizing data
const resources = {
categories: [
{ name: 'Category X', items: [ { id: 0, title: 'Item X'} ] },
{ name: 'Category Y', items: [ { id: 1, title: 'Item Y'} ] },
]
};
//Fetching the item
const itemId = 1;
const category = resources.categories.find(c => c.items.find(i => i.id === itemId));
const item = category.items.find(i => i.id === itemId);
//Displaying the result
console.log(item);
While the above implementation is functional, I believe there could be a more efficient approach to retrieving an object from an array, especially when needing to repeat the code multiple times...