vendredi 26 mai 2017

(jQuery) check if array value empty

I'm trying to check if array beda[i].person.name value is empty. But it keeps ignoring it. I can't figure out what I'm doing wrong with if statement

$.ajax({
    url: link,
    method: 'GET',
    success: function (beda) {
        console.log(beda);

        for(var i = 0; i < beda.length; i++){
           $("ul").first().append( "<li>" + beda[i].person.name + " ... " + beda[i].character.name + "</li>");
           console.log(beda[i].person.name)

        if ( beda[i].person.name == '' ||  beda[i].person.name == null ||  beda[i].person.name == undefined || beda[i].person.name.lenght == 0) {
            $("ul").first().append( "<li>" + "No names found!" + "</li>");
     }
    }
  }
});

Aucun commentaire:

Enregistrer un commentaire