Looks For-In To Me


var languages = {
english: “Hello!”,
french: “Bonjour!”,
notALanguage: 4,
spanish: “Hola!”

// print hello in the 3 different languages
for(var property in languages){
if(typeof languages.property===“string”)

why it doesnot work?
if i changed it into [];
it works .but i remember that [] and . are the same result .why it is different?

for(var property in languages){
if(typeof languages[property]===“string”)


the dot notation:


only works for properties, but the for in loop stores the properties as string in loop iterator, and for strings (or variable like the loop iterator which contains strings) we need to use square brackets notation

language."english" // doesn't work
langues["english"] // works


ok,thank you for your explanation.


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