I have a function that loops through an Object's keys until the key matches a keyword within the input. After finding a match, how can I then loop through the matched Object keys values ?
let obj = {
music: {
"do you like music": "Yes I do",
"what music do you like": "Jazz"
},
sports: {
"Do you like sports": "Yes"
}
};
let input = "i like music";
function run(input) {
let newStr = input.split(' ');
let key = Object.keys(obj);
key.forEach((key) => {
newStr.forEach((str) => {
if (key === str) {
console.log(key)
}
});
});
};
run(input);
if(str in obj)and then just log the str since it is the same as the key, no loops needed.