gpt4 book ai didi

javascript - 嵌套 JavaScript 数组的分隔列表

转载 作者:行者123 更新时间:2023-12-01 02:34:08 25 4
gpt4 key购买 nike

我有一个简单的 JavaScript 对象,其中包含嵌套数组。我在这里寻找的只是返回“digitalData.transaction.item.productInfo[i].productID[j]”中存在的“productID”值的逗号分隔列表

非常感谢您的帮助。

这是一个 JS 的示例(抱歉,篇幅较长,但我猜,这样比抱歉更好):

window.digitalData = {
transaction: {
purchaseID: "30010819", //Typically the same as transactionID
transactionID: "30010819", //Unique Identifier for this transaction
item: [{ //Array of items in this transaction
productInfo: {
productID: "63493",
color: "Fuscia", //color if this product has colors
size: "M (8-10)", //size if this product has sizes
sku: "63493-12456", //sku
inventoryStatus: "In Stock", // Mirror the on-site messaging
skuAttr: [{ // extensible array of sku attributes and values
typeLabel: "Color",
valueCode: "FSA",
valueLabel: "Fuscia"
}, {
typeLabel: "Size",
valueLabel: "M (8-10)"
}]
},
price: {
currency: "USD"
},
quantity: 1
}, {
productInfo: {
productID: "55027",
color: "", //color if this product has colors
size: "", //size if this product has sizes
sku: "55027", //sku if known. otherwise use productID
inventoryStatus: "Low Stock", // Mirror the on-site messaging
skuAttr: [] //Empty array if no sku attributes exist
},
price: {
currency: "USD"
},
quantity: 2
}]
}]
}

最佳答案

你可以这样做:

digitalData.transaction.item.map(x => x.productInfo.productID).join(',')

关于javascript - 嵌套 JavaScript 数组的分隔列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48065375/

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