Cannot read property 'push' of undefined when combining arrays

前端 未结 8 2157
轮回少年
轮回少年 2021-02-01 12:18

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

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

8条回答
  •  别跟我提以往
    2021-02-01 12:36

    This error occurs in angular when you didn't intialise the array blank.
    For an example:

    userlist: any[ ];
    this.userlist = [ ]; 
    

    or

    userlist: any = [ ];
    

提交回复
热议问题