Combine the values of two arrays into object

前端 未结 5 1601
遥遥无期
遥遥无期 2021-01-21 08:43

I have two arrays:

array1 = [\"Bob\", \"John\", \"Dave\"];
array2 = [1, 2, 3];

Is there combine the two into a javascript array filled with obj

5条回答
  •  感动是毒
    2021-01-21 09:24

    Assuming you're using Chrome, you could do:

    const combined = array1.map((name,i) => ({meta: name, value: array2[i]}))

提交回复
热议问题