I’m not seeing why this isn’t working. I commented my thought process which is that if collection[i]
has the property in source
then it would push collection[i]
to arr
.
I feel maybe I’m not doing something right with the fact that these are objects? It might be checking if the entire collection has the source? Please let me know, thanks
**Your code so far**
function whatIsInAName(collection, source) {
var arr = [];
// Only change code below this line
// loop through collection
for (let i = 0; i < collection.length; i++) {
// if collection includes source then push it to arr
if (collection[i].hasOwnProperty(source)) {
arr.push(collection[i]);
}
}
// Only change code above this line
return arr;
}
console.log(whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" }));
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36
.
Challenge: Wherefore art thou
Link to the challenge: