How to Use Array.indexOf() for Comparing Multiple Items in JavaScript
We are all familiar with the Logical OR Operator (||). One of the most common uses of the OR operator is to compare one value to several other values in a condition.
Let's look at an example:Write a function that takes the name of a month as an argum...
dushmanta.hashnode.dev3 min read
You can also use
Array.includes():function checkMonth (month) { const compareMonths = ['January', 'March', 'May', 'July', 'August', 'October', 'December']; // we can use ternary instead of if ...else return compareMonths.includes(month) ? `${month} has 31 days` : `${month} doesn't have 31 days`; } console.log(checkMonth ('July')); // "July has 31 days" console. log (checkMonth ('February')) // "February doesn't have 31 days"