2017-04-25 55 views
0

我已经使用map在reactjs中创建了两个数组。第一个是使用javascript中的地图创建两个数组的数组

const hey = portfolioSectorsPie.map(sector => sector.subtotal); 
const hello = portfolioSectorsPie.map(sector => sector.percentage) 

哎格式=的招呼[22, 23, 25] 格式= [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)%]与百分比下降的元素嘿。有任何想法吗?

+0

'[22(22.35)%,23(22.67)%,25(25.90)%]'这是你的数组,你需要得到'[22,23,25 ],[22.35,22.67,25.90]'? – Oen44

+1

不清楚它是什么意思'[22,23,25](22.35)%(22.67)%,(25.90)%或者[22(22.35)%,23(22.67)%,25(25.90)%] '。 – dfsq

+0

不,我想创建一个包含这两个值的数组。另外我想第二个值在第一个值下,但我无法正确写入。 – user7334203

回答

0

对于每个可以在这里有所帮助。

看看这个JSBIN

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); 
+0

不错的,谢谢!但是,如何像我的情况一样表现出你好? – user7334203

+0

@ user7334203我不确定“show hello down of h”是什么意思。你能详细说明一下吗?我很乐意提供帮助。 –

+0

@ user7334203:你在这里 - https://jsfiddle.net/abhitalks/qycLzbxu/ :) – Abhitalks