Multiply all elements in array

前端 未结 7 460
不思量自难忘°
不思量自难忘° 2020-12-05 10:16

I couldn\'t find an example here what I\'m really looking for. I\'d like to multiply all array elements, so if an array contains [1,2,3] the sum would be 1*2*3=6; So far I\'

相关标签:
7条回答
  • 2020-12-05 10:51

    Using Lodash >=4.7:

    _.reduce(array, _.multiply)
    

    or, using all three arguments:

    _.reduce(array, _.multiply, 1)
    
    0 讨论(0)
提交回复
热议问题