Skip to content
Advertisement

Is there a way to only show selected property in a json object based on a array

I have the following object

JavaScript

It has alot more property but for simplicity sake ill just show 3 properties. I also have the follow array [Title,number]

Now basing from the array I only want to show object property based on my array. My results should be

JavaScript

Advertisement

Answer

You could map the wanted properties as objects, collect them to a single object and mapp all objects for a new array.

JavaScript

The same with a destructuring assignment and short hand properties.

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