Wherefore art thou -

Here’s what I have so far:

function whatIsInAName(collection, source) {
  var filtered = collection.filter(value => value.last == Object.values(source));
  return filtered;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });

How can I make ‘value.last’ dynamic? The following loop gives me what I want, but I don’t know how to implement it into the code above.

  for (var i = 0; i < collection.length; i++) {
    var names = Object.keys(collection[i]);
  }

Link to the challenge:
learn . freecodecamp . org /javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou

@camperextraordinaire Well if I do console.log(source.last) it gives me “Capulet” and changing it to Object.values(source) makes it dynamic.

var filtered = collection.filter(value => value.last == Object.values(source));

The code above works for the first test, but fails on the second one as the keys have different names:

whatIsInAName([{ "apple": 1 }, { "apple": 1 }, { "apple": 1, "bat": 2 }], { "apple": 1 });

I could manually adjust it to value.apple, but obviously I don’t wanna do that. I want to have a placeholder in there that will dynamically get the right key name:

var filtered = collection.filter(value => value.apple == Object.values(source));

Appreciate the thorough response! Gonna give it another shot later today.