JavaScript flex

const people = [ { name: 'Sara', age: 25, gender: 'f', us: true }, { name: 'Mike', age: 18, gender: 'm', us: false, }, { name: 'Peter', age: 17, gender: 'm', us: false, }, { name: 'Ricky', age: 27, gender: 'm', us: false, }, { name: 'Martha', age: 20, gender: 'f', us: true } ];
// Filter every element of this array let women = people.filter(function(person) { // only return the objects that have the key gender equal to f return person.gender === 'f'; }

To test it

Cool tip: In cases like this you can use console.table instead of console.log to get a table as the output instead of getting the object references.

let women = people.filter((person) => person.gender === 'f');

No comments:

The Weekender: November shadows, bike thievery, and a sculptural pavlova

What we’re reading, watching, and listening to this week ͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ...

Contact Form

Name

Email *

Message *