Skip to content
Advertisement

Map + filter – Showing people that have < 18 years and abbreviate names

I wanted to be able to transform the age into a single array, so I would already know how to filter, then apply the mapping to only show people over 18 years old, in addition, to present the abbreviated names of the people.

JavaScript

Here what i tried to do:

JavaScript

Advertisement

Answer

If I’m understanding correctly the desired outcome is [Ra, Ma]?

If so you can .filter.map.

JavaScript

You can also chain these…

JavaScript

That said your amantesGatos is an object with a bunch of duplicate keys and not an array. Which means it’s really an object with only the last name and age. For example…

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