Intro to Object 2 - Q27 (How to store the property'value ?)


#1

I understand x is the name of each property, but how can I access each x's value ?

var languages = {
english: "Hello!",
french: "Bonjour!",
notALanguage: 4,
spanish: "Hola!"
};

// print hello in the 3 different languages
for(var x in languages){
var xValue =
if(typeof ){

}

}


#2

to do that you can do this.
object[property]
Take a look at the example i have below:

//define the object
var lang = {
  english : "Hello",
  french : "Bonjour",
  spanish: "ola"
};
// loop through your object
//c is the poperty and the object value can access by calling object[property]
for(var c in lang){
  console.log("In " + c + " we say '" + lang[c] + "'");
}

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.