Are Javascript arrays sparse?

后端 未结 7 2148
情书的邮戳
情书的邮戳 2020-11-22 08:12

That is, if I use the current time as an index into the array:

array[Date.getTime()] = value;

will the interpreter instantiate all the elem

7条回答
  •  醉酒成梦
    2020-11-22 08:43

    Javascript objects are sparse, and arrays are just specialized objects with an auto-maintained length property (which is actually one larger than the largest index, not the number of defined elements) and some additional methods. You are safe either way; use an array if you need it's extra features, and an object otherwise.

提交回复
热议问题