开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜