Javascript - Sum two arrays in single iteration

后端 未结 13 2099
我寻月下人不归
我寻月下人不归 2020-11-29 05:56

I want to sum each value of an array of numbers with its corresponding value in a different array of numbers, and I want to do this without looping through each individual v

13条回答
  •  天涯浪人
    2020-11-29 06:12

    You can do it using some functional style:

    const a = [1,2,3]
    const b = [4,5,6]
    
    const f= a.concat(b).map((v,i,arr)=>{
      if ( i!isNaN(n))
    
    console.log(f)
    

提交回复
热议问题