Uncaught TypeError: data.push is not a function

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

    Also make sure that the name of the variable is not some kind of a language keyword. For instance, the following produces the same type of error:

    var history = [];
    history.push("what a mess");
    

    replacing it for:

    var history123 = [];
    history123.push("pray for a better language");
    

    works as expected.

提交回复
热议问题