[{
"name": "employeeOne",
"age": 22,
"position": "UI",
"city": "Chennai"
},
{
"name": "employeeTwo",
"age": 23,
"position": "UI",
"city": "Bangalore"
}
]
如果我删除“位置” json中的键和值,结果应该像[
[{
"name": "employeeOne",
"age": 22,
"city": "Chennai"
}, {
"name": "employeeTwo",
"age": 23,
"city": "Bangalore"
}]
如果我们在表中有员工列表,我只想删除所有员工职位列。如何使用JavaScript和Typescript实现此目标
我尝试过
const output = delete employee.position
但出现错误。
答案 0 :(得分:0)
您那里有一系列对象。您将不得不遍历数组,分别删除每个对象中的属性。
答案 1 :(得分:0)
看看删除操作
伪:
JSONArray中的foreach obj
{
删除obj [“ position”];
}
也可以:
obj [position]
obj.position
答案 2 :(得分:0)
var data = [{
"name": "employeeOne",
"age": 22,
"position": "UI",
"city": "Chennai"
},
{
"name": "employeeTwo",
"age": 23,
"position": "UI",
"city": "Bangalore"
}
];
data.forEach( item => {delete item.position;});
console.log(data);