Could someone give some insight as to why my return array doesn’t keep the quotes around the property values? What step in my code is removing them??
Disclaimer: I know my logic is flawed and using Object.keys
makes more sense. And I also know with my current code it wont get passed the second check. But it’s bugging me that my return isn’t what I expect it to be.
My code so far:
function whatIsInAName(obj, tobj){
let returnArr = [];
let targetProp;
let targetValue;
for (let extract in tobj){
targetProp = extract
targetValue = tobj[extract]
};
for (let i in obj){
for(let prop in obj[i]){
if (obj[i].hasOwnProperty(prop) && prop == targetProp && obj[i][prop] == targetValue){
returnArr.push(obj[i])
}
}
}
console.log(returnArr)
/*
for some reason this logs returnArr as:
[ { apple: 1 }, { apple: 1 }, { apple: 1, bat: 2 } ]
without any " "
*/
};
whatIsInAName([{ "apple": 1 }, { "apple": 1 }, { "apple": 1, "bat": 2 }], { "apple": 1 })
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Wherefore art thou
Link to the challenge: