var a = [{'id':1,'name':'James','age':11}];
a = a.filter(function( obj,i ) {
//return obj != 'age';
});
filter will create a new array, but how to splice away the age property key? Didn't use jquery, can't use $.grep in this case. and won't use delete because it's not really delete the key but leave an empty slot.
Use Array#forEach and delete operator to delete the key
var a = [{
'id': 1,
'name': 'James',
'age': 11
}, {
'id': 2,
'name': 'James2'
}];
a.forEach(function(obj, i) {
obj['age'] && delete obj['age'];
});
console.log(a);
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