dimanche 29 novembre 2015

Trying to print only string data

I'm trying to get the for-loop and if statement to just print out string data only.

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

// print hello in the 3 different languages
for (var x in languages) {
    if (typeof x === "string") {
        console.log(languages[x])
    }
};

Aucun commentaire:

Enregistrer un commentaire