🎁 Join my channel to get access to perks:
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
// 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.
🔹currentValue : The value of the current element. On first call, the value of array if an initialValue was specified, otherwise the value of array.
🔹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 : https://www.facebook.com/Code.Explained.Official
◾ Twitter : https://twitter.com/code_explained
◾ Instagram : https://www.instagram.com/Code.Explained.Official/
◾ GitHub : https://github.com/CodeExplainedRepo