I'm trying to get a value from an object and I just can't get it.
The maximum I get is that,have
using console.log(randomWords)
I'm sure I'm doing something wrong here, but I already spent some long hours trying to find the error. The object looks fine and I just can't find a way to access these deep values.
var words = {
"that": {
"languages": {
"pt": {
"multiple_meanings": true,
"meaning": ["aquilo", "aquela"]
},
"it": {
"multiple_meanings": false,
"meaning": "quella"
}
}
},
"this": {
"languages": {
"pt": {
"multiple_meanings": true,
"meaning": ["este", "esta"]
},
"it": {
"multiple_meanings": true,
"meaning": ["questo", "questa"]
},
}
}
};
var userChoseLanguage = "pt"
var wordsKeysArr = Object.keys(words).toArray;
var wordIndex = Math.floor(Math.random() * wordsKeysArr.length);
//store a random word in randomWord
var randomWord = recipesKeysArr[factIndex];
//if user chose pt
if(userChoseLanguage == "pt"){
//if multiple_meanings = true
if(randomWord.languages.multiple_meanings===true) {
console.log("This word has more than one meaning");
}
else {
console.log(randomWord.languages.meaning);
}
}