Answers for "JavaScript Array Methods .reduce()"

0

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
Posted by: Guest on July-21-2021
1

JavaScript Array Methods .reduce()

const list = [1, 2, 3, 4, 5];
console.log(list.reduce((number, nextNumber) => number + nextNumber));
// --> 15
Posted by: Guest on May-07-2021

Code answers related to "JavaScript Array Methods .reduce()"

Code answers related to "Javascript"

Browse Popular Code Answers by Language