mercredi 11 décembre 2019

Check multiple strings shorter, JS?

I want to check a string if it matches one or more other strings. In my example i just used 4 possible string values. How can i write this code shorter if i have to check for more values?

//Possible example strings: "ce", "c", "del", "log"
let str = "log"; //My input
console.log(str == "log" || str == "del" || str == "c" || str == "ce"); //Return if str has a match

Aucun commentaire:

Enregistrer un commentaire