Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const people = [
- { "id": 1, "first_name": "Sunshine", "last_name": "Vesty", "email": "svesty0@latimes.com", "gender": "Female", "ip_address": "183.111.102.72", "vehicles": "Scion" },
- { "id": 2, "first_name": "Allyce", "last_name": "Heatley", "email": "aheatley1@ustream.tv", "gender": "Female", "ip_address": "250.195.26.202", "vehicles": "Toyota" },
- { "id": 3, "first_name": "Tanitansy", "last_name": "Bazley", "email": "tbazley2@canalblog.com", "gender": "Female", "ip_address": "208.37.216.91", "vehicles": "Mercury" },
- { "id": 4, "first_name": "Gustavo", "last_name": "Macy", "email": "gmacy3@hp.com", "gender": "Male", "ip_address": "43.110.63.96", "vehicles": "Ford" },
- { "id": 5, "first_name": "Arley", "last_name": "Allom", "email": "aallom4@pen.io", "gender": "Male", "ip_address": "168.59.248.11", "vehicles": "Mazda" },
- { "id": 6, "first_name": "Connie", "last_name": "Espada", "email": "cespada5@opensource.org", "gender": "Male", "ip_address": "43.12.37.107", "vehicles": "Lexus" },
- { "id": 7, "first_name": "Philippine", "last_name": "Voak", "email": "pvoak6@taobao.com", "gender": "Female", "ip_address": "144.91.4.160", "vehicles": "GMC" },
- { "id": 8, "first_name": "Jojo", "last_name": "Albasini", "email": "jalbasini7@bluehost.com", "gender": "Female", "ip_address": "255.44.68.78", "vehicles": "Ford" },
- { "id": 9, "first_name": "Francesco", "last_name": "Thorlby", "email": "fthorlby8@ucoz.ru", "gender": "Male", "ip_address": "14.45.191.100", "vehicles": "Ford" },
- { "id": 10, "first_name": "Weider", "last_name": "Bensley", "email": "wbensley9@live.com", "gender": "Male", "ip_address": "133.50.241.33", "vehicles": "Lotus" }
- ];
- // filter array of objects with desired property
- const filteredPeople = Object.keys(people).filter((key) => people[key]['vehicles'] === 'Ford');
- // map returns a new array, forEach does not
- const peopleWithFord = filteredPeople.map(x => people[x]);
- console.log(peopleWithFord);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement