forum

Home / DeveloperSection / Forums / What is Object Splicing Array?

What is Object Splicing Array?

Tom Cruser 1831 24-Nov-2014

In my application i want to splice objects from an array upon matching, I am using lodash function for splicing like as shown below, unfortunately the json is not splicing correctly,

Can anyone give me some suggestion for this issue

var arr = [{
    name: 'kamlakar',
    id: 1001
}, {
    name: 'kamlakar',
    id: 1001
}];

 var result = _.without(arr, _.findWhere(arr, {name: 'kamlakar'}));

console.log(JSON.stringify(result));

Expected result

[]

Actual Result

[{"name":"kamlakar","id":1001}]

Update 1

Even using normal JavaScript way also giving the same output

for(var i = 0; i < arr.length; i++) {
    var obj = arr[i];
 
    if(obj.name === 'kamlakar') {
        arr.splice(i, 1);
    }
}


Updated on 25-Nov-2014

Can you answer this question?


Answer

1 Answers

Liked By