我有像这样的对象
{
"6":{
"id":2045,
"categories":[
{
"id":7,
"name":"Day Trips & Excursions Outside the City"
},
{
"id":2,
"name":"Day-Tour"
},
{
"id":8,
"name":"Food, Wine & Gastronomy"
}
],
},
"8":{
"id":2045,
"categories":[
{
"id":7,
"name":"Day Trips & Excursions Outside the City"
},
{
"id":2,
"name":"Day-Tour"
},
{
"id":8,
"name":"Food, Wine & Gastronomy"
}
],
},
},
现在我只想删除每个对象,如果它的属性(id)与用户提供的id匹配
[2045, 1234]
所以在这种情况下,我想删除id为2045或1234
的对象 I tried multiple solution but failed, I just want to update the object something
const categorytobedeleted = [2045, 12345];
for(const v of categorytobedeleted) {
const newobject = Object.values(oldobject).map(function(x) {
return x
}).indexOf(v);
Object.values(oldobject).slice(newobject, 1)
}
this.oldobject = this.newobject // maybe old object recreated with newly created object after deleting
答案 0 :(得分:1)
您可以将var MainController = function($scope) {
$scope.variable = 'text';
console.log('other text');
}
用于此目的:
reduce