Skip to content
Advertisement

How can I find objects with same keys values in array?

I have an array of objects that looks like this:

JavaScript

And I need to find objects with the same type to merge fields key in them, like this:

JavaScript

My plan was to filter through the array, but my problem is that I don’t know which type will send me API, so filtering by item.type wouldn’t work for me.

Advertisement

Answer

If that is the exact solution that you want. Following code snippet may help you.

JavaScript

This will print

JavaScript
Advertisement