smooll
smooll

Reputation: 15

How to search through an array without making multiple if statements?

So I have an if statement:

if (logMessages.author.username === botName[0]) {
   return;
}

How can I search through an array of 4 strings without making 4 different if statements?

I hope this is enough of an explanation.

Upvotes: 0

Views: 160

Answers (1)

Nisarg Shah
Nisarg Shah

Reputation: 389

There are multiple ways to find elements in an array.

I can see that you only need to find whether the element exists or not. For that, the best option would be to use .includes(). Example : arrayName.includes("variable")

For other options, please have a look here.

Upvotes: 1

Related Questions