I have an API which returns me a collection which needs to be reordered for better performance later in code. Now, I'm wondering should I leave as collection of objects
var collection = [{
"id": "d3d2d",
"something": "win"
}, ...]
and use for later on:
for(var i in collection){bla = collection[i]something;}
or as a object
var object = {
"d3d2d": {
"something": "win"
}
};
So that I can later use it like this
bla = object[i.need.id].something;
My point is if I use data as an object, I don't need to use "for" later in code. So which way will be faster? I need to note that later in code I need to compare a lot of data and I have really small response time!
EDIT1: Yes, ID's are unique.
EDIT2: Array vs. Object efficiency in JavaScript, thx @Daria
EDIT3: I need to iterate through arrays when I fetch them and I can use a lot of time to prepare data, BUT I need to save time once someone fetch data from me then I have around 20ms to do this and bunch of other stuff.