Free views, likes and subscribers at YouTube. Now!
Get Free YouTube Subscribers, Views and Likes

reduce Method | JavaScript Array Methods | Beginners tutorial

Follow
Code Explained

Join my channel to get access to perks:
   / @codeexplained  

Hello All JavaScript Lovers Outhere!

Today you're going to learn about the Array Object In JavaScript.

This tutorial is a series of videos, in each video we will discuss a method (or more) of the Array Object in JavaScript.

In today's video, you're going to learn about the reduce method.

The reduce() method executes a reducer function for array element.
The reduce() method returns a single value: the function's accumulated result.
The reduce() method does not execute the function for empty array elements.
The reduce() method does not change the original array.

The Array.reduce().
Syntax :
// Callback function
reduce(callbackFn)
reduce(callbackFn, initialValue)

// Inline callback function
reduce(function(previousValue, currentValue, index, array) { /* … */ })

callbackFn : A "reducer" function called with the following arguments:
previousValue : The value resulting from the previous call to callbackFn. On first call, initialValue if specified, otherwise the value of array[0].
currentValue : The value of the current element. On first call, the value of array[0] if an initialValue was specified, otherwise the value of array[1].
currentIndex : The index position of currentValue in the array. On first call, 0 if initialValue was specified, otherwise 1.
array : The array being traversed.
initialValue (Optional) : A value to which previousValue is initialized the first time the callback is called. If initialValue is specified, that also causes currentValue to be initialized to the first value in the array. If initialValue is not specified, previousValue is initialized to the first value in the array, and currentValue is initialized to the second value in the array.


Social Media Links.
◾ Facebook :   / code.explained.official  
◾ Twitter :   / code_explained  
◾ Instagram :   / code.explained.official  
◾ GitHub : https://github.com/CodeExplainedRepo

Suppport the Channel
Paypal : https://paypal.me/CodeExplained
Buy Me a Coffee: https://www.buymeacoffee.com/CodeExpl...

posted by Haglichfn