---
title: "Comment by Nauris on \"JavaScript check if array contains a value\" | Hashnode"
description: ".includes() method is definitely my favorite way of checking if array contains a value, it makes code that much more readable. indexOf() is the &quot;old way&qu"
url: "https://hashnode.com/posts/javascript-check-if-array-contains-a-value/61f262f3805bdf3ebd486fbd/comment/61f2e2ed22a38747671d6cd6"
---

[Discussion](https://hashnode.com/posts/javascript-check-if-array-contains-a-value/61f262f3805bdf3ebd486fbd)

Comment [JavaScript check if array contains a value](https://hashnode.com/posts/javascript-check-if-array-contains-a-value/61f262f3805bdf3ebd486fbd)

[Nauris](https://hashnode.com/@pyronaur)

[Jan 27, 2022](https://hashnode.com/posts/javascript-check-if-array-contains-a-value/61f262f3805bdf3ebd486fbd/comment/61f2e2ed22a38747671d6cd6)

`.includes()` method is definitely my favorite way of checking if array contains a value, it makes code that much more readable.

`indexOf()` is the "old way" of doing it because `includes()` is only supported in IE Edge 14+ (no IE11 support).

But when targeting modern browsers, or a transpiler or node.js - `includes()` is the way to go.

Fun fact - you can also use it on strings to check if string includes a value too:

```
"Does foobar".includes("foo")
// true
```

[Chris Bongers](https://hashnode.com/@dailydevtips)

[Jan 28, 2022](https://hashnode.com/posts/javascript-check-if-array-contains-a-value/61f262f3805bdf3ebd486fbd/comment/61f2e2ed22a38747671d6cd6#reply-61f390cd22a38747671d79f6)

Yep very true indeed :)
