Answers for "The reduce() method executes a reducer function on each element of the array and returns a single output value."

0

The reduce() method executes a reducer function on each element of the array and returns a single output value.

const message = ["JavaScript ", "is ", "fun."];

// function to join each string elements
function joinStrings(accumulator, currentValue) {
  return accumulator + currentValue;
}

// reduce join each element of the string
let joinedString = message.reduce(joinStrings);
console.log(joinedString);

// Output: JavaScript is fun.
Posted by: Guest on April-14-2022

Code answers related to "The reduce() method executes a reducer function on each element of the array and returns a single output value."

Browse Popular Code Answers by Language