All VideosJavaScript Tutorials

How to sum of array values? JavaScript Tutorials in Hindi | JS Interview Question #4

In modern versions of JavaScript (ES5 and above), you can use the reduce method of an array to calculate the sum. This is frontend developer interview question. In JavaScript Tutorials in Hindi series we will cover all the important interview questions.

In this approach, the reduce method is called on the arr array. The first argument to reduce is a function that takes two arguments: an accumulator (a) and the current element of the array (c), and returns the sum of the accumulator and the current element. The result of reduce is the final value of the accumulator, which is the sum of all the elements in the array.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!