我有一个json对象集合如下。
[
{"FirstName":"Test1","LastName":"User","Email":"test@test.com","City":"ahmedabad","State":"sk","Country":"canada","Status":"False","iUserID":"23"},
{"FirstName":"user","LastName":"user","Email":"u@u.com","City":"ahmedabad","State":"Gujarat","Country":"India","Status":"True","iUserID":"41"},
{"FirstName":"Ropbert","LastName":"Jones","Email":"Robert@gmail.com","City":"NewYork","State":"gfg","Country":"fgdfgdfg","Status":"True","iUserID":"48"},
{"FirstName":"hitesh","LastName":"prajapti","Email":"h.prajapati@zzz.com","City":"","State":"","Country":"","Status":"True","iUserID":"78"}
]
现在我想从所有这些对象中删除一些属性(例如,Email& city)而不使用循环。有人可以指导我如何在javascript中以更好的方式做到这一点?
答案 0 :(得分:2)
您可以使用delete
运算符和Array.prototype.forEach
这样的
objects.forEach(function(currentItem) {
delete currentItem["Email"];
});
答案 1 :(得分:0)
您可以使用正则表达式从JSON字符串中删除属性:
s = s.replace(/,"Email":"(\\"|[^"])*","City":"(\\"[^"])*"/, '');