I have an object as follows:
var dataSources = [
{
Stage: [2, 3, 4],
Name: "GetAustralianStateList"
},
{
Stage: [2, 3, 4],
Name: "GetGenderList"
},
{
Stage: [2, 3, 4],
Name: "GetTitleList"
},
{
Stage: [2, 3, 4],
Name: "GetCountryList"
},
{
Stage: [2, 3, 4],
Name: "GetRegionList"
},
{
Stage: [2, 3, 4],
Name: "GetNonEnglishLanguageList"
},
{
Stage: [2, 3, 4],
Name: "GetContactRelationshipList"
},
{
Stage: [3, 4],
Name: "GetCompanyCodeList"
},
{
Stage: [3, 4],
Name: "GetBusinessContractList"
},
{
Stage: [3, 4],
Name: "GetPayrollAreaList"
},
{
Stage: [3, 4],
Name: "GetAdministrationAreaList"
},
{
Stage: [3, 4],
Name: "GetWorkContractList"
},
{
Stage: [2, 3, 4],
Name: "GetFirstLanguageList"
},
];
When I call dataSources.length in Chrome it returns the correct number of items in the object. However Internet Explorer returns a length of 14 – 1 more than is actually in the object.
Any ideas?
Unfortunately you’ve discovered one of the very few bugs in ECMAScript implementations: IE treats a single trailing comma in an array literal as an elision, so it increments the length by one:
The above shows that IE treats the comma as an elision: the length has been increased by one but there is no member of the array at index 2.