---
title: "Comment by Tanner Wiltshire on \"How to Use Array.indexOf() for Comparing Multiple Items in JavaScript\" | Hashnode"
description: "You can also use Array.includes() : function checkMonth ( month ) { const compareMonths = [ &#x27;January&#x27; , &#x27;March&#x27; , &#x27;May&#x27; , &#x27;Ju"
url: "https://hashnode.com/posts/using-arrayindexof-to-compare-multiple-items-in-javascript/6390cfdbf5b5cff009e54789/comment/6390de5a120246e215ffa153"
---

[Discussion](https://hashnode.com/posts/using-arrayindexof-to-compare-multiple-items-in-javascript/6390cfdbf5b5cff009e54789)

Comment [How to Use Array.indexOf() for Comparing Multiple Items in JavaScript](https://hashnode.com/posts/using-arrayindexof-to-compare-multiple-items-in-javascript/6390cfdbf5b5cff009e54789)

[Tanner Wiltshire](https://hashnode.com/@Taouen)

[Dec 7, 2022](https://hashnode.com/posts/using-arrayindexof-to-compare-multiple-items-in-javascript/6390cfdbf5b5cff009e54789/comment/6390de5a120246e215ffa153)

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"
```

[Dushmanta](https://hashnode.com/@dushmanta)

[Dec 8, 2022](https://hashnode.com/posts/using-arrayindexof-to-compare-multiple-items-in-javascript/6390cfdbf5b5cff009e54789/comment/6390de5a120246e215ffa153#reply-63914eec0771b6e5cf4a6be3)

Yes! Thank you for letting me know. I'll try to implement this method next time; it looks more clean.
