I would like to know if it is possible to create an array and initialize it with the same object without having to loop on each element. I don't want to loop because i could have to insert many element . this is what i would like to be able to do:
var array=new Array(10000);
and I would like that each element of the array is the same object (other than undefined :) ) without having to do like this
for(i=0;i<array.length;i++)
array[i]=object;
I hope that i want to do is clear to you
I came up with a solution but i uses the eval function so I am not sure if it is the best but it much efficient than a loop
Your advises are welcomed :)
here is how
var i="l,",l=new Object(),length=20000;
l.id=1;
while(i.length<length){
i+=i;
}
i=i.substring(0,length-1);
i="["+i+"]";
var array=eval(i);
console.log(array);
thanks