Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

reduce javascript

// use of reduce on an array, returns an array into a single value

// define the array
let numbers = [25, 25, 20]

// using the .reduce() to ADD all the numbers into a single value
// we are storing the reduce method into a single variable called sum
let sum = numbers.reduce(function(total, current) {
	return total + current // adds the current value (10) and the total value (0) 
}, 0); // the }, 0) is important because we want our total value to be 0.
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #reduce #javascript
ADD COMMENT
Topic
Name
3+2 =