+ 2
Javascript Advanced Methods. Could someone please tell me what is reduce actually used for ?
2 Respostas
+ 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
0
Reduce an array to a single value or another array, object.