Skip to content
Advertisement

How to Combine 2 Array with same key

I have 2 array like this …

JavaScript

Then I want to combine and group all the same key (“Name”), so that the end result looks like this…

JavaScript

How can I achieve this?

Advertisement

Answer

I created distinct names array. And then in a for loop for each of the names, searched the index for that name in both array $a and $b. That gave the values for total sell and total buy for each names. And created array $c with relevant information.

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