I've created an array in JavaScript and inserted objects with keys of object_ids:
var ar = [];
ar[4] = 'a';
ar[2] = 'b';
ar[8] = 'c';
ar[5] = 'd';
Problem is when I print this out the array I get is:
[undefined, undefined, "b", undefined, "a", "d", undefined, undefined, "c"]
and
ar.length = 9
How do I prevent the array from auto filling with undefined
values and simply save this array as a 4-element array?
Iteration over an array is not what I expect here.
Thanks!