-2

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

I need to remove all value of array which have "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()
}
user944513
  • 9,790
  • 23
  • 109
  • 225
  • U could try it easily!! refer http://stackoverflow.com/questions/5767325/remove-specific-element-from-an-array – Navaneet Jun 11 '15 at 19:18

3 Answers3

0

Can you try this function to remove all value of array which have "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)
        }
    }
}
Tom
  • 6,751
  • 1
  • 20
  • 42
0

Slight error in incrementing k

for(var i=0; i<arr.length;i++){
    for (var k=0; k<arr[i].columns.length;k++)
    delete arr[i].columns[0]
}

Updated JS Fiddle

Sunil B N
  • 3,866
  • 1
  • 25
  • 46
0

you can use Underscore.js

var result = _.map(arr, function(obj){ 
                return {
                    columns: _.reject(obj['columns'], function(innerObj){
                                return innerObj['fieldNameOrPath'] == 'Id';
                            })
                }
            });
Gurbakhshish Singh
  • 964
  • 1
  • 8
  • 23