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

Modern browsers have Array#includes, which does exactly that and is widely supported by everyone except IE:  Run code snippet You can also use Array#indexOf, which is less direct, but doesn’t require polyfills for outdated browsers.  Run code snippet Many frameworks also offer similar methods: jQuery: $.inArray(value, array, [fromIndex]) Underscore.js: _.contains(array, value) (also aliased as _.include and _.includes) Dojo Toolkit: dojo.indexOf(array, value, [fromIndex, findLast]) Prototype: array.indexOf(value) MooTools: array.indexOf(value) MochiKit: findValue(array, value) MS … Read more