Reputation: 7490
I have an array of objects in a web application, the values of which get updated several times. Im trying to work out the best/fastest way
I have a jsPerf here - http://jsperf.com/marker-assignment-test The 'normal' test is how Im currently doing it.
Anyone have any ideas for a faster method?
EDIT: the 'normal' test is how I have it in the web application, but I want to optimise it. The only thing that can not change, is that the objects are stored in an array, and that several values will need updating at the same time
Upvotes: 0
Views: 203
Reputation: 75307
Variables are extremely cheap in JavaScript, so you should look at using them. I've cached the result of myArray[1]
in a variable, and it's quicker than your tests.
If you have many objects in the array, you should also look at optimizing the iteration of the array; Are loops really faster in reverse?
Upvotes: 2