Uncaught TypeError: data.push is not a function

前端 未结 8 1514
半阙折子戏
半阙折子戏 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:05

    I think you set it as

    var data = []; 
    

    but after some time you made it like:

    data = 'some thing which is not an array'; 
    

    then data.push('') will not work as it is not an array anymore.

提交回复
热议问题