Search
 
SCRIPT & CODE EXAMPLE
 

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.
Comment

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

const numbers = [1, 2, 3, 4, 5, 6];

function sum_reducer(accumulator, currentValue) {
  return accumulator + currentValue;
}

let sum = numbers.reduce(sum_reducer);
console.log(sum); // 21

// using arrow function
let summation = numbers.reduce(
  (accumulator, currentValue) => accumulator + currentValue
);
console.log(summation); // 21
Comment

PREVIOUS NEXT
Code Example
Javascript :: setstate 
Javascript :: ForEach Element with Function or Lambda 
Javascript :: option selected aotu value 
Javascript :: react native ant design 
Javascript :: array.length in mongoose query 
Javascript :: tailwind rn npm install 
Javascript :: horizontal tabs in react js 
Javascript :: how to search and filter js 
Javascript :: $[name] in jquery 
Javascript :: if event keycode and click 
Javascript :: directive multiple input 
Javascript :: get query params from url 
Javascript :: how to create an html element in javascript without document 
Javascript :: Warning: Internal React error: Expected static flag was missing. Please notify the React team. 
Javascript :: debug javascript in chrome 
Javascript :: search node in tree javascript 
Javascript :: como checar valor do input checkbox angular 
Javascript :: push array into array javascript 
Javascript :: vue-router beforeeach 
Javascript :: find element in an array and replace it by a callback function 
Javascript :: javascript dom after a element 
Javascript :: call a javascript function at a specific time of day 
Javascript :: angularjs ng-options name value 
Javascript :: npm: Create react chrome extension 
Javascript :: js get folder of current script 
Javascript :: unknown provider angularjs 
Javascript :: node-fetch graphql 
Javascript :: .push js 
Javascript :: react to pdf 
Javascript :: reset reactive state vue 3 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =