I want to use a specific string in addition to a number to the index of array,
I make like this
var array = new Array();
$(document).ready(function(){
array = addToArray();
console.log("array size " + array.length);
});
function addToArray(){
var i = 0;
var tmpArray = new Array();
while(i<10){
if(i>9){
addToArray();
i++;
}
else{
tmpArray["elem"+i] = "i";
console.log(tmpArray["elem"+i]); // It prints out!!!
i++;
}
}
console.debug(tmpArray);
return tmpArray;
}
When I print out the tmpArray, it's empty. Also the size is 0. When I remove the "elem" from the index of the array, it works properly. What should I do?
Here's a real example: http://jsfiddle.net/dfg3x/