Currently, I have an array of objects, that looks like this:
var arr = [{
id: UNIQUE_ID,
title: 'TITLE'
}, {
id: UNIQUE_ID,
title: 'TITLE'
}];
What is bothering me here, is that in particular cases I have to loop through the array and display data for matching ID. I want to just fetch everything for that particular object, thas has the ID I want, and that's it. It would be a lot easier for me if the array looked more like this:
var arr = [{
id: {
title: 'TITLE'
},
id: {
title: 'TITLE'
}
}]
The ID comes from a result of a method that generates a random number, so I'll need to put a variable or a method call for this id.
I'm not sure this is possible, since I found no particular example on this, but I'd like to hear another solutions as well.
my_data[key]to access objects. You lose the ability to do "array-like" things like push and pop, but if you don't need them, just use an object.