First of all, JS engines are different on every browser, so they don't perform equally on every case.
Also, you have to take in mind that arrays in JavaScript are Objects too, the only difference is that they have integers as their key values to simulate the indexes.
When you create an array with just one element at a high index the Object will be created with all the other "spaces" filled with undefined
values so the JS engine have to traverse the whole structure to find your value.
As @RobG says, the native array methods like reduce
, map
, and forEach
will perform a lot better in this case.
Also you can use functional libraries like Ramda or Lodash to help you traverse and flatten your queries results.