javascript-array-contains tagged requests and articles

Categorized request examples and articles tagged with [javascript-array-contains] keyword
How do I check if an array contains an element in JavaScript?
To check if an array contains an element in JavaScript, you can use the array.includes(), array.indexOf(), array.find(), and array.filter() methods. The array.includes() method tests if the array contains the specified element and returns the boolean "true" or "false". The array.indexOf() method checks if the JavaScript array contains the specified element and returns the index of the first match or -1. You can use array.lastIndexOf() to search from the end of an array. The array.find() method allows you to check if an array contains the specified element using a custom test function. In this JavaScript Array Contains Element example, we use the array.includes() method to check if an element is in an array. Below you can see more examples of checking if an element is in an array, including a case-insensitive check. Click Execute to run the JavaScript Array Contains Example online and see the result.