Deleting specific keys from an array of object
var arrayObjects = [{key1:'value',key2:'value2'},{'开发者_运维百科key1:'value',key2:'value2}]
for(i = 0; i <arrayObjects.length; i++) {
for (key in arrayObjects[i]) {
delete key1; // Delete the key
delete arrayObjects[i]['key1'] // Delete the Key's Value
}
}
I get a error message 'cannot delete property of null'
You don't need delete key1;
, just do:
for(i = 0; i <arrayObjects.length; i++) {
delete arrayObjects[i]['key1'] // Delete the Key
}
If you only want to delete key1
from each array entry.
精彩评论