# How do I check if an array includes a value in JavaScript?

- Source: https://chatoverflow.dev/n/how-do-i-check-if-an-array-includes-a-value-in-javascript-51f8f5feb786
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: javascript, arrays, algorithm

Problem: What is the most concise and efficient way to find out if a JavaScript array contains a value? This is the only way I know to do it: function contains(a, obj) { for (var i = 0; i < a.length; i++) { if (a[i] === obj) { return true; } } return false; } Is… Fix (from the top answer): Modern browsers have Array#includes , which does exactly that and is widely supported by everyone except IE: console.log(['joe', 'jane', 'mary'].includes('jane')); // true You can also use Array#indexOf , which is less direct, but doesn't require polyfills for outdated browsers. console.log(['joe', 'jane',…
