gpt4 book ai didi

javascript - 从 json 中删除对象的一些值

转载 作者:行者123 更新时间:2023-11-30 11:34:21 24 4
gpt4 key购买 nike

我有这个 json-

"SkuList": [
{
"active": null,
"id": 698027,
"productSKUName": "v1",
"productSKUDescription": null,
"productSKUId": "02ffea0f-3d05-44"
},
{
"active": null,
"id": 698028,
"productSKUName": "v2",
"productSKUDescription": null,
"productSKUId": "628acbb9-0bdb-4ccf"
},
]

我如何过滤这个 json 并返回这个 -

"brandProductSkuList": [
{

"id": 698027,
"productSKUId": "02ffea0f-3d05-4436",
},
{

"id": 698028,
"productSKUId": "628acbb9-0bdb-4ccf"
},
]

我想删除对象的某些属性。我该怎么做?

最佳答案

你可以使用 map为此:

var SkuList = [
{
"active": null,
"id": 698027,
"productSKUName": "v1",
"productSKUDescription": null,
"productSKUId": "02ffea0f-3d05-44"
},
{
"active": null,
"id": 698028,
"productSKUName": "v2",
"productSKUDescription": null,
"productSKUId": "628acbb9-0bdb-4ccf"
},
];

var brandProductSkuList = SkuList.map((sku) => ({
id: sku.id,
productSkuId: sku.productSKUId
}));

console.log(brandProductSkuList);

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

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