What is the best structure solution for find element(Object) in Object Array by value of one of the keys.
For example we have array:
var someArray =
[
{id:17, color:'black', width:50},
{id:34, color:'red', width:150},
{id:49, color:'gree', width:10}
]
and we need to find an Object with id-key = 34.
And each time we will have to do the loop to find the object. I thought about restructuring and having object instead of array like so:
var someObject =
{
17: {id:17, color:'black', width:50},
34: {id:34, color:'red', width:150},
49: {id:49, color:'gree', width:10}
}
Now we can do it in one step someObject[34], BUT what if we want to keep the order?
Thanks in advance.