i have an array = [] and it contains objects... obj, obj, obj. I have to remove obj two, but i don't know the index... so how can i remove obj. the name of the object is also same.
The ES5 way to do this is with Array.filter
myarray = myarray.filter(function(val, index, a) {
return (val !== obj);
});
See the MDN page linked above for a version to use if you don't have ES5.
Technically this creates a new array, rather than modify the original array. However splice as proposed in other answers isn't particularly efficient anyway since it has to renumber all of the indices above each matching element, and will do so over and over if there's more than one match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With