mardi 30 juin 2020

if --- else javascript

What I want is to call function b with parameter arr1, if arr1 has at least one value in it, else if arr1 is empty call function b with parameter arr2. However the else block is not calling function b when arr1 is empty.

function a(){
    let arr1 = [];
    let arr2 = [];
    if(arr1){
        b(arr1);
    }
    else {
        b(arr2);
    }   
}

function b(arr){
    doSomething with arr;
}

Aucun commentaire:

Enregistrer un commentaire