Closed
Description
In js it is possible to create arrays with unset values.
Example:
var data = [0,,,'3'];
In this case the data
array's 1
and 2
properties should not exist.
data.hasOwnProperty(1) == false
data.hasOwnProperty(2) == false
Currently both the 1 and 2 is set to undefined which is incorrect.
However the data.length
should be 4
and when accessing the data[1]
and data[2]
should return undefined
Testcase:
var data = [0,,,'3'];
if (!(data.hasOwnProperty(0) && data.hasOwnProperty(3))
{
print("Error, index 0 and 3 does not exist");
}
if (data.hasOwnProperty(1) !== false)
{
print("Error, index 1 should not be set");
}
if (data.hasOwnProperty(2) !== false)
{
print("Error, index 2 should not be set");
}
if (data.length !== 4)
{
print("Error, array's length should be 4");
}