Tuesday, June 12, 2018

JavaScript - Array Methods - reduce

Below code demonstrates the usage of array method:
  • reduce
var Arr1 = [1,2,3,4,5,6,7];


console.log("total = "+0+" ; value = "+Arr1[0]);

function performReduction(total,value)  {
  console.log("total = "+total+" ; value = "+value);
  return total + value;
}

reducedOutput = Arr1.reduce(performReduction);

console.log("total = "+reducedOutput+" ; value = "+"");

console.log(reducedOutput);

Refer:  https://docs.microsoft.com/en-us/scripting/javascript/reference/reduce-method-array-javascript

Practice at: http://jsbin.com

No comments:

Post a Comment