https://jsfiddle.net/a5t24gm3/1/
Search thousands of free JavaScript snippets that you can quickly copy and paste into your web pages. Get free JavaScript tutorials, references, code, menus, calendars, popup windows, games, and much more.
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');
Taking Down a Nuclear War Liar
A lie can get halfway around the world before the truth can get it shoes on ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏...