This isn´t working and I don´t understand why:
var arr=[];
for(var i=0; i < 12; i++){
arr.push[i]}
This isn´t working and I don´t understand why:
var arr=[];
for(var i=0; i < 12; i++){
arr.push[i]}
What are you returning or logging to the console?
Push is a function so it should be called with parentheses. The brakes are for accessing an element in an array. You don’t need that here because push creates a new element at the end. Instead of the push, you could have also done arr[i] = i
. But in this case arr.push(i)
should do the same thing, if I understand your intention.
Ahh, I didn’t even catch that, and I should have. I was thinking that maybe they were returning or logging to the console arr.push(), which would be the length of the array rather than the modified array itself. Overthought it, I guess.