Does null occupy memory in javascript?

后端 未结 4 1013
孤城傲影
孤城傲影 2020-12-09 03:30

I\'ve got the following situation:

var large = [a,b,c,d,e,f,g,h,i];
var small = [a2, b2, c2, null, null, null, null, null, null, i2];

where

4条回答
  •  悲&欢浪女
    2020-12-09 03:53

    Why not just put the small items into large[2].small? Anyway, you usually don't have to worry about memory consumption in javascript, but still it is better to leave the unused positions in small undefined (which is something else than setting them to undefined!), so that javascript engine can decide to switch to sparse array (represented by a hashtable instead of an array).

提交回复
热议问题