0

I have two arrays

array1=[1,2,3]

array2=['one','two','three']

I want the result to be

res=[[1,'one'],[2,'two'],[3,'three']]

[end of problem] The below line was added just to meet the question posting rules:

I tried looking it up online but did not find anything, I can do it in python,but still a beginner in javascript

1 Answers1

2

you can use array.map ... one of many ways though :)

const array1=[1,2,3]

const array2=['one','two','three']

const res = array1.map((el,idx)=> [el,array2[idx]])

console.log(res)
KcH
  • 3,302
  • 3
  • 21
  • 46