In JavaScript when you define an array using the literal syntax, array elements may be omitted by using additional commas:
a = [1, 2, 3]; // 1, 2, 3
b = [1, , 2, 3]; // 1, undefined, 2, 3
I noticed that when accessing the values that the omitted values were not "own properties"
b.hasOwnProperty(1); //false
In contrast, if you define an array explicitly setting undefined
, it will be set as an "own property":
c = [1, undefined, 2, 3];
c.hasOwnProperty(1); //true
Is the behavior for how omitted array elements are assigned defined in a spec? If so, which spec and where?
(optional bonus) Is it reliable cross-browser, such as evidenced by compatibility tables?