Not sure how to exactly use this .filter() with an arrow function.
Instructions:
Use the built in filter method to filter over the jobs array of objects and return the object of the person with a job as a programmer. Make sure to use the arrow function in conjunction with the filter method.
Tried Solution:
var jobs = [{receptionist: "James"},
{programmer: "Steve"},
{designer: "Alicia"}];
var solution = jobs.filter(person => person === "programmer");
You can do it by many ways e.g by using in, using includes() and so on. But If I were you I'll try this way using hasOwnProperty
The hasOwnProperty() method returns a boolean indicating whether the object has the specified property as its own property (as opposed to inheriting it).
var jobs = [{
receptionist: "James"
},
{
programmer: "Steve"
},
{
designer: "Alicia"
}
];
var solution = jobs.filter(obj => obj.hasOwnProperty('programmer'));
console.log(solution)
With in:
var jobs = [{receptionist: "James"},
{programmer: "Steve"},
{designer: "Alicia"}];
var solution = jobs.filter(obj => 'programmer' in obj);
console.log(solution)
With includes:
var jobs = [{receptionist: "James"},
{programmer: "Steve"},
{designer: "Alicia"}];
var solution = jobs.filter(obj => Object.keys(obj).includes('programmer'));
console.log(solution)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With