vendredi 4 décembre 2015

if else comparing array to string

I have the following if-else:

if (entity.length > depot.length) {
    for (var i = 0 ; i < entity.length; i++) {
        promises.push(this.getDataFromREST(security, i));
        console.log(entity, depot)
    }
} else {
    for (var i = 0 ; i < depot.length; i++) {
        promises.push(this.getDataFromREST(security, i));
        console.log(entity, depot)
    }
}

Where entity and depot are arrays, but if they are not holding data they = "NULL".

Basically,for the purposes of this explanation, I want the length of "NULL" to be read as 0, or if entity is an array of length 1+ and depot is a string - the condition entity.length > depot.length is met.

Aucun commentaire:

Enregistrer un commentaire