Skip to content
Advertisement

Get object from array of objects depending on a specific property

Lets say we have the following:

JavaScript

how can I sort this by cat? so that I can then do something like

JavaScript

note: cat is unique

Thanks

Advertisement

Answer

You can use .reduce:

JavaScript

or .map and Object.entries:

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