To access the data in the array, I created an enum variable to have human-readable identifiers for the fields.
var columns = { first: 0, second: 1 }; var array = ['first', 'second']; var data = array[columns.first];
When I found out about Object.freeze , I wanted to use this for enumeration so that it could not be changed, and I expected the virtual machine to take advantage of this information.
As it turns out, tests become slower in Chrome and Node, but slightly faster in Firefox (compared to direct access by number).
The code is available here: http://jsperf.com/array-access-via-enum
Here are the tests from Node (corresponding to the JSPerf tests):
fixed Number: 12ms enum: 12ms frozenEnum: 85ms
Does V8 not yet have a great implementation, or is there something suboptimal with this approach for my use?
source share