Looks For-In To Me




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

// print hello in the 3 different languages
for (var x in languages) {
    if (typeof languages.x === "String") {
    else {

I can't print out the type.. it says 'undefined'.


the for in loop stores the properties of object as string, so you have to use associative array notation (square brackets)

also, typeof will return "string" and that doesn't equal "String" (comparison is case sensitive)


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