Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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.
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #The #method #executes #reducer #function #element #array #returns #single #output
ADD COMMENT
Topic
Name
3+7 =