[英]how to remove object from array using javascript or angular js?
I am trying to remove object from array and get the resulted array.I am using remove function but it is not working perfectly Here is my input我正在尝试从数组中删除对象并获取结果数组。我正在使用 remove 函数,但它无法正常工作这是我的输入
I need to remove all value of array which have "file": "Id"
我需要删除具有
"file": "Id"
所有数组值"file": "Id"
here is my fiddle这是我的小提琴
for (var i = 0; i < arr.length; i++) {
for (var k = 0; i < arr[i].columns.length; i++)
arr[i].columns[0].remove()
}
Can you try this function to remove all value of array which have "file": "Id"
您可以尝试使用此函数删除具有
"file": "Id"
的数组的所有值吗
for(var i=0; i<arr.length;i++){
for (var k=0; k < arr[i].columns.length; k++){
if(arr[i].columns[k].fieldNameOrPath == 'Id'){
arr[i].columns.splice(k,1)
}
}
}
Slight error in incrementing k
递增
k
轻微错误
for(var i=0; i<arr.length;i++){
for (var k=0; k<arr[i].columns.length;k++)
delete arr[i].columns[0]
}
you can use Underscore.js你可以使用Underscore.js
var result = _.map(arr, function(obj){
return {
columns: _.reject(obj['columns'], function(innerObj){
return innerObj['fieldNameOrPath'] == 'Id';
})
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.