如果我想从下面的示例中删除一个Json对象,该怎么办?
{ Name : "abc",
EMail : "abc@gmail.com"
Fruits : [{
Name : "name",
family: "Z"
},
{
Name : "name",
family: "A"
},
{
Name : "name",
family: "B"
},
{
Name : "name",
family: "C"
}
]
}
如果我想删除{ Name : "name", family: "C" }
,请从上面的示例中获取。我知道家庭= C并且它是独一无二的。
如何使用JavaScript在Aws DynamoDB中实现这一目标?
答案 0 :(得分:0)
var data = {
"Name" : "abc",
"EMail" : "abc@gmail.com",
"Fruits" : [{
"Name" : "name",
"family": "Z"
},
{
"Name" : "name",
"family": "A"
},
{
"Name" : "name",
"family": "B"
},
{
"Name" : "name",
"family": "C"
}
]
}
data.Fruits = data.Fruits.filter(val => ((val.Name == "name" && val.family != "C") || (val.Name != "name" && val.family == "C")));
console.log(data);