Tell us what’s happening:
This is the start of the simplest approach I’m trying to do, but it’s returning nothing.
I’m hoping to loop through the objects in collection, and if an object has source (hasOwnProperty), I want to push the object to arr.
I realize that one issue is that source can have more than one key, value pair.
Your code so far
function whatIsInAName(collection, source) {
var arr = [];
// Only change code below this line
for (var i = 0; i < collection.length; i++){
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36
.
Challenge: Wherefore art thou
Link to the challenge: