Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js reduce

// syntax: array.reduce(function, accumulator-initial-value)
let array = [3, 7, 2, 9, 5]
const result = array.reduce((accumulator, currentValue, currentIndex, arr) => {
  // code
}, initialValue)

// accumulator = will store return value of the function
// currentValue = iterate through each array element
// currentIndex = index of currentValue
// arr = original array
// initialValue = set accumulator initial value
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #js #reduce
ADD COMMENT
Topic
Name
2+9 =