Cannot read property 'push' of undefined when combining arrays
Asked 07 September, 2021
Viewed 2.2K times
  • 62
Votes

When pushing an array's contents to another array I get


  

"Uncaught TypeError: Cannot read property 'push' of undefined" error in this snippet.

var order = new Object(), stack = [];
for(var i=0;i<a.length;i++){
    if(parseInt(a[i].daysleft) == 0){ order[0].push(a[i]); }
    if(parseInt(a[i].daysleft) > 0){ order[1].push(a[i]); }
    if(parseInt(a[i].daysleft) < 0){ order[2].push(a[i]); }
}

Why do I get this error in the second if statement ? Thanks a lot!

9 Answer