wcrase
1
Tell us what’s happening:
I am having trouble with getting the array string to find the variable you are searching for.
Your code so far
function whatIsInAName(arr,source) {
let arrString = JSON.stringify(arr);
let sourceString = JSON.stringify(source);
console.log(arrString);
console.log(sourceString);
for (let obj in arr) {
console.log(arrString.includes(sourceString))
}
}
console.log(whatIsInAName(
[
{ first: "Romeo", last: "Montague" },
{ first: "Mercutio", last: null },
{ first: "Tybalt", last: "Capulet" }
],
{ last: "Capulet" }
)
) //should return [{ first: "Tybalt", last: "Capulet" }]
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Implement a Matching Object Filter - Implement a Matching Object Filter
Teller
2
Hi @wcrase
I commented out the console logs. Your function is returning undefined.
You need to return something. Write down in words what you want the function to do.
Once you understand what is required, start writing code that does those things.
Happy coding
1 Like
What’s the purpose of using stringify here?
for (let obj in arr) {
console.log(arrString.includes(sourceString))
}
In your editor you may notice that obj is a different color. This indicates that you never refer to obj in that block of code, in the for loop.
wcrase
4
stringify was to compare the objects as strings, how do I compare the two stringified objects successfully?
wcrase
5
oh wait, was it because the stringified objects were outside of the loop?
from your console.log output
[{"first":"Romeo","last":"Montague"},{"first":"Mercutio","last":null},{"first":"Tybalt","last":"Capulet"}]
{"last":"Capulet"}
Is that what you were expecting? It’s an array not a string, right?
EDIT: Ah, my mistake it is a string.
However look at your source string:
'{"last":"Capulet"}'
Look at it as a complete string. Do any of your inputs contain that entire string?