gpt4 book ai didi

javascript - 从数组中删除一个对象

转载 作者:行者123 更新时间:2023-12-02 16:39:40 24 4
gpt4 key购买 nike

从下面给定的对象中删除名为“itemType”的属性的方法是什么?

 {
"id": 19,
"cost": 10,
"items": 10,
"numbers": 10,
"status": false,
"hours": 10,
"itemType": {
"id": 16,
"name": "PC 350",
"description": "PC 350"
},
"typeid": 12
}

最终的数组应该是这样的

 {
"id": 19,
"cost": 10,
"items": 10,
"numbers": 10,
"status": false,
"hours": 10,
"typeid": 12
}

最佳答案

这是对象而不是数组。您可以像这样使用删除

   var obj = {
"id": 19,
"cost": 10,
"items": 10,
"numbers": 10,
"status": false,
"hours": 10,
"itemType": {
"id": 16,
"name": "PC 350",
"description": "PC 350"
},
"typeid": 12
}

delete obj.itemType;

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

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