[removed] using typeof to check if string

前端 未结 6 1916
萌比男神i
萌比男神i 2021-02-14 15:32

I\'m working on a codecademy.com exercise where we use for-in statements to loop through an object and print hello in different languages by checking to see if the values of the

6条回答
  •  名媛妹妹
    2021-02-14 16:15

    The below coding is also useful to perform only string value.By using variable to access the property list of abject after that by using it check the value is a NotANumber by using isNaN.The code given below is useful to you

    var languages = {
    english: "Hello!",
    french: "Bonjour!",
    notALanguage: 4,
    spanish: "Hola!"
    };
    
    // print hello in the 3 different languages
    for(a in languages)
    {
    if(isNaN(languages[a]))
    console.log(languages[a]);
    }
    

提交回复
热议问题