Uncaught TypeError: data.push is not a function

前端 未结 8 1501
半阙折子戏
半阙折子戏 2020-12-04 23:45

I am trying to push

data.push({\"country\": \"IN\"});

as new id and value to a json string. but it gives the following error



        
8条回答
  •  一向
    一向 (楼主)
    2020-12-05 00:04

    Your data variable contains an object, not an array, and objects do not have the push function as the error states. To do what you need you can do this:

    data.country = 'IN';
    

    Or

    data['country'] = 'IN';
    

提交回复
热议问题