Skip to content
Advertisement

How to remove the lower values in a list of object arrays in js

I want to keep the highest bitrate for each type of quality, so 1080p will keep the one with itag 137, and 720p will keep the itag with 398.

Here is my list with object arrays

JavaScript

Advertisement

Answer

You can use the Array.prototype.reduce() Method to reduce an array by iterating all items and returning the outgoing result.
In this case, we want to keep an Item of each quality. Therefore we reduce the Array by pushing items their qualities arent yet into the resulting array.

For further clarification and in depth details I always recommend to view the documentation of MDN Web Docs:
MDN Docs – Array.prototype.reduce()

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