There are no string array keys in JavaScript, such as PHP and some other languages. What you did was add a property with a name elem + ito the object tmpArray. This does not affect the property of the array .length, although the property exists and is available, and it is not available using array methods such as.pop(), .shift()
, tmpArray , - .
function addToArray() {
var i = 0;
var tmpObj = {};
while(i<10) {
if(i>9) {
addToArray();
i++;
}
else {
tmpObj["elem"+i] = "i";
console.log(tmpObj["elem"+i]);
i++;
}
}
console.debug(tmpObj );
return tmpObj ;
}