-1

I have this array:

var arr = [];
var i =
Nahid Hasan
  • 613
  • 1
  • 8
  • 29

1 Answers1

3

1) There:

setInterval ( function push(arr) {arr.push(i+1)} , 5*1000)

you're shadowing the arr variable (that is declaring a new variable which hides the external one). You're thus pushing to undefined. There's of course the same problem when you read the values.

2) If you always push i+1 you always push 1. You probably want i++

Simply do

setInterval ( function push() {arr.push(i++)} , 5*1000)
Denys Séguret
  • 355,860
  • 83
  • 755
  • 726