Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中使用map从两个数组创建一个数组_Javascript_Arrays_Reactjs - Fatal编程技术网

在javascript中使用map从两个数组创建一个数组

在javascript中使用map从两个数组创建一个数组,javascript,arrays,reactjs,Javascript,Arrays,Reactjs,我使用map在reactjs中创建了两个数组。第一个是 const hey = portfolioSectorsPie.map(sector => sector.subtotal); const hello = portfolioSectorsPie.map(sector => sector.percentage) hey=[22,23,25] hello=[22.35、22.67、25.90] 我想创建一个具有以下格式的数组: finalArr = [22, 23, 25]

我使用map在reactjs中创建了两个数组。第一个是

const hey = portfolioSectorsPie.map(sector => sector.subtotal);
const hello = portfolioSectorsPie.map(sector => sector.percentage)
hey=
[22,23,25]
hello=
[22.35、22.67、25.90]
我想创建一个具有以下格式的数组:

finalArr = [22, 23, 25]
         (22.35)% (22.67)%, (25.90)%

这可能会让人困惑,但想象一下这样的数组
[22(22.35)%,23(22.67)%,25(25.90)%]
,其中的百分比是hey的元素数。有什么想法吗?

这里对每个人都有帮助

看看这个


[22(22.35)%,23(22.67)%,25(25.90)%]
这是您的数组,您需要从该数组中获取
[22,23,25],[22.35,22.67,25.90]
吗?不清楚它的意思是什么
[22,23,25](22.35)%,(25.90)
。或者
[22(22.35)%,23(22.67)%,25(25.90)%
。不,我想创建一个包含这两个值的数组。另外,我希望第二个值位于第一个值之下,但我无法正确写入它。数组将一个接一个地包含元素,如果您想在ui中显示它,那么您需要在ui中处理它,而不是在数组创建期间。好的,我想知道在javascriptNice one中是否有这样做的方法,谢谢!但是如何像我的案例那样在h下面显示hello?@user7334203我不知道你所说的“在h下面显示hello”是什么意思。你能详细说明一下吗?我很乐意帮忙。@user7334203:给你--:)
const hey = [20,40,60]
const hello = [23.4, 23.5, 36.5];

let retArr = [];
hey.forEach( (h, i) =>
  retArr.push(`${h} (${hello[i]})`)
)

console.log(retArr);