Uncaught TypeError: data.push is not a function

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

    one things to remember push work only with array[] not object{}.

    if you want to add Like object o inside inside n

    
    
    a={ b:"c",
    D:"e",
    F: {g:"h",
    I:"j",
    k:{ l:"m"
    }}
    }
    
    a.F.k.n = { o: "p" };
    a.F.k.n = { o: "p" };
    console.log(a);

提交回复
热议问题