How to use reduce in js array
This article mainly introduces how to use reduce in the js array, which is very detailed and has a certain reference value. Interested friends must read it!
1. The reduce () method executes a reducer function on each element in the array and summarizes the results into a single return value.
2. It takes two parameters, a reducer function that provides each call to the array, and an optional initial value parameter.
Example
Find the sum of array items
Var sum = arr.reduce (function (prev, cur) {return prev + cur;}, 0)
Find the maximum value of the array item
Var max = arr.reduce (function (prev,cur) {return Math.max (prev,cur);}); these are all the contents of the article "how to use reduce in js arrays". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!