+ 2

Javascript Advanced Methods. Could someone please tell me what is reduce actually used for ?

7th Jun 2019, 7:35 AM
Sudarshan Rai
Sudarshan Rai - avatar
2 Respuestas
+ 1
it does what it says. it reduces the array. for eg when you want the sum of the elements of an array, you can use the reduce method to do so. var arr=[1,3,4]; var sum=arr.reduce(function(accumulator, currentValue) { return accumulator+currentValue; }); alert(sum); // 8
7th Jun 2019, 7:59 AM
Farry
Farry - avatar
0
Reduce an array to a single value or another array, object.
7th Jun 2019, 8:57 AM
Calviղ
Calviղ - avatar