【发布时间】:2018-01-20 23:38:10
【问题描述】:
我有对象数组,我正在尝试遍历该数组,如果找到匹配项,我想对该对象进行切片..
var object = [
{
"Name": 'Kshitij',
"LastName": 'Rangari',
"CountryBorn": 'India',
"CountryStay": 'USA'
},
{
"Name": 'Pratik',
"LastName": 'Rangari',
"CountryBorn": 'India',
"CountryStay": 'Canada'
},
{
"Name": 'Pratibha',
"LastName": 'Rangari',
"CountryBorn": 'India',
"CountryStay": 'India'
},
{
"Name": 'Ankita',
"LastName": 'Raut',
"CountryBorn": 'India',
"CountryStay": 'Australia'
},
{
"Name": 'Wayne',
"LastName": 'Rooney',
"CountryBorn": 'UK',
"CountryStay": 'UK'
}
]
console.log(object);
object.forEach(function(x){
if (x.Name==='Kshitij'){
}
})
object.map (obj =>{
obj.AllFirstName = obj['Name'];
console.log(obj['AllFirstName']);
})
console.log('------------------------------')
console.log(object);
我想遍历 Object 并想找到 Name === 'Kshitij' 和 Name ==='Pratik',我想从数组中删除这些对象。
我该怎么做?
【问题讨论】:
-
arr.forEach(function callback(currentValue, **index**, array) ...)。此外,虽然调用数组object在技术上是正确的,但这里有点误导。 -
这个正确的术语不是“切片”。它正在“过滤掉”。
标签: javascript arrays