首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >嵌套JavaScript数组中的分隔列表

嵌套JavaScript数组中的分隔列表
EN

Stack Overflow用户
提问于 2018-01-03 01:34:50
回答 1查看 54关注 0票数 0

我有一个包含嵌套数组的简单JavaScript对象。我在这里要做的就是返回一个逗号分隔的列表,其中包含"digitalData.transaction.item.productInfoi.productIDj“中的”productID“值

我很感谢你的帮助。

下面是JS的一个例子(很抱歉篇幅太长,但我想这总比抱歉要好):

代码语言:javascript
复制
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     
      }]
    }]
  }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-03 01:41:08

你可以这样做:

代码语言:javascript
复制
digitalData.transaction.item.map(x => x.productInfo.productID).join(',')
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48065375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档