gpt4 book ai didi

javascript - 从对象数组中删除特定键

转载 作者:行者123 更新时间:2023-11-28 16:29:15 25 4
gpt4 key购买 nike

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

}

}

我收到错误消息“无法删除 null 的属性”

最佳答案

您不需要delete key1;,只需执行以下操作:

for(i = 0; i <arrayObjects.length; i++) {
delete arrayObjects[i]['key1'] // Delete the Key
}

如果您只想从每个数组条目中删除key1

关于javascript - 从对象数组中删除特定键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6749414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com