I have this array:
var arr = [];
var i =
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)