我有这样的json:json = [ { "value1":"3863", "value2":"4567" }, { "value1":"4456", "value2":"87687" }, { "value1":"98494", "value2":"4534" }, ]我需要的是删除 value2 以便 json 看起来像:json = [ { "value1":"3863" }, { "value1":"4456" }, { "value1":"98494" }, ]我试过用for(var i = 0; i < json.length; i++){ delete json["value2"]; }但它不起作用。有没有办法做到这一点?
3 回答
皈依舞
TA贡献1851条经验 获得超3个赞
const json = [
{
"value1":"3863",
"value2":"4567"
},
{
"value1":"4456",
"value2":"87687"
},
{
"value1":"98494",
"value2":"4534"
},
];
json.forEach(item => delete item.value2);
慕运维8079593
TA贡献1876条经验 获得超5个赞
您只是错过i了访问 json 数组元素的用法:
for(var i = 0; i < js.length; i++)
{
delete json[i]["value2"];
}
添加回答
举报
0/150
提交
取消