Skip to content
Advertisement

How to get sum of array values according to some index (non-sorted)

I want the sum of monthly_rental and arc if the month and full_name are the same in one array.

Input Array

JavaScript

There are 6 sub-arrays in 1st and 2-nd indexes, I want the sum of 0,1,5 (Ritesh Shah, Month 2) array and make them unique. Same as this I have a long list of the array but I will manage them all if any of you just suggest to me how to get sum value of this array.

OUTPUT That I want :

JavaScript

Advertisement

Answer

You can apply this function and retrieve your expected output:

JavaScript

Demo

Or a little bit different:

JavaScript

Demo2

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement