Search code examples
arraysextjssencha-architect

EXTjs Changing 3 values to single array


Trying to get familiar with extJS arrays and having some issues setting this up, I currently have the following code...

 if(!multiLine){
    phe = deviceType.search(check1);
    if(phe !== -1){phoneExists = true;}

    phe = deviceType.search(check2);
    if(phe !== -1){phoneExists = true;}

    phe = deviceType.search(check3);
    if(phe !== -1){phoneExists = true;}
}
return phoneExists;

Instead of simply checking 3 times separately, how can I check it all at once in an array?


Solution

  • This is more of a Javascript question than extJS question. You could use Array.some method to check that at-least one element is found:

    var devices = [check1, check2, check3]
    var phoneExists = devices.some(x => deviceType.search(x) >= 0)
    

    More on the Array.some