从 JS Map 获取第一个值

Get First Value From JS Map

我有这个代码映射到一个 JS 对象数组

 marketplaceData.map((marketplace) => {
      const { primarySaleCount, secondarySaleCount } = marketplace;
      console.log(primarySaleCount);
})

return 值:

primarySaleCount -> 905, 459
secondarySaleCount -> 394, 291

我只想抓取其中一个对象,然后像这样分别显示它们:

<Chart
          data={[
            [
              "Platform 1",
              parseInt(primarySaleCount),   //desiredValue -> 905. //actualValue ->905
              parseInt(secondarySaleCount), //desiredValue -> 394.  //actualValue ->392
            ],
            [
              "Platform 2",
              parseInt(primarySaleCount), //desiredValue -> 459.   //actualValue -> 905
              parseInt(secondarySaleCount), //desiredValue ->291.  //actualValue ->394
            ],

          ]}
/>

基本上,我的 marketplaceData 映射中的 return 值在 primarySaleCount 变量中为我提供了两个字符串。我希望以某种方式将正在 returned 的两个 primarySaleCount 字符串分开,这样我就可以在 (secondarySaleCount 也是如此)

谢谢

primarySaleCount -> "905, 459"
secondarySaleCount -> "394, 291"

var primarySaleCountNumbers = primarySaleCount.split(','); //this will give you an array ['905', '459']

var secondarySaleCountNumbers= secondarySaleCount.split(',') //this will give you an array ['394', '291']

你可以像这样在你的平台上传递这些,

parseInt(primarySaleCountNumbers[0]) //To pass 905 wherever you want
parseInt(primarySaleCountNumbers[1]) //To Pass 459 

同样适用于 secondarySaleCount

<Chart
          data={[
            [
              "Platform 1",
              parseInt(primarySaleCountNumbers[0]),   
              parseInt(secondarySaleCountNumbers[0]), 
            ],
            [
              "Platform 2",
              parseInt(primarySaleCountNumbers[1]), 
              parseInt(secondarySaleCountNumbers[1]),
            ],

          ]}
/>