I'd like to set #currentWord span to the hovered over Chinese word's English translation.
To do that, I'm storing words based on their category in an object:
var vocab = {
"pronouns" :
{
'wǒ' : 'I',
'nǐ' : 'You',
},
"nouns" :
{
'gǒu' : 'dog'
},
"verbs" :
{
'bāng' : 'help',
'xún' : 'search',
}
};
I then call parseHoveredText to send the word to the currentWord span:
$("#currentWord").text(parseHoveredText(word));
parseHoveredText() Function:
function parseHoveredText (word) {
for (obj in vocab) {
log(vocab[obj][word]);
return vocab[obj][word];
}
return "";
};
When I hover over "Ni", it correctly outputs the English "You"

Console output is also correct: You
However: Hovering over bang (in the "verbs" object) outputs nothing:

Console output shows: Undefined
The weird thing is: If I comment out //return vocab[obj][word];, the console outputs the correct associated English, "Help", but still doesn't display it to the span...
Why is that?
Thanks!