I want to fill inner array of two dimensional array with items at specific index. The problem in this case is that every inner array is filled with that items.
Try: link_to_code_img
Result: link_to_result_img
the code:
Array.prototype.repeat= function(what, L){
while(L) this[--L]= what;
return this;
};
var yearsdays = [].repeat([], 365);
for(var i = 0; i<= yearsdays.length; i++){
if(i === 99) {
yearsdays[i].push(99)
}
}
the result:
Array[365]
[0 … 99]
0: Array[1]
0: 99
length: 1
__proto__: Array[0]
1: Array[1]
0: 99
length: 1
__proto__: Array[0]
2: Array[1]
0: 99
length: 1
__proto__: Array[0]
and etc.......
The problem is that as a result every array in yearsdays was filled with number 99, but not only array with index 99 as I expect. What am I doing wrong?