>我有这个代码通过一个JS对象数组映射
marketplaceData.map((marketplace) => {
const { primarySaleCount, secondarySaleCount } = marketplace;
console.log(primarySaleCount);
})
返回值:
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
],
]}
/>
基本上,我的市场数据映射的返回值在 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]),
],
]}
/>