简体   繁体   中英

Two dimensional array from single dimensional arrays not working

I have two arrays

A=['a','b','c',...] 
B=[1,2,3...]

Array length of A=B. I need a resultant array like this

R= [['a',1],['b',2],['c',3],...]

I tried like this

for(var i=0;i< A.length;i++)
{
 R.push(A[i],B[i])
}

It is not working. What should I do?? I am new to this. Please help me. I searched a lot, but not getting. Help me dear friends!!

Change

R.push(A[i],B[i])

to

R.push([A[i],B[i]])

因为您希望 R[] 是一个二维数组,所以您必须将程序稍微更改为:

R.push([A[i], B[i]])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM