Search for a value in an array through JavaScript

What is the most concise and efficient way to find out if a JavaScript array contains a value?

Last updated:7/20/2021 1:43:54 AM

1 Answers

Ethan Karla
Ethan Karla

In JavaScript, includes() method determines whether a string contains the given characters within it or not.

This method returns true if the string contains the characters, otherwise, it returns false. The includes() method is case sensitive i.e. ,it will treat the Uppercase characters and Lowercase characters differently.

Let's understand it with the help of an example :

<!DOCTYPE html>

<html>
<body>
    <p id='demo'></p>
    <script>
        var str = 'Mindstick Software Private Limited';
        var check = str.includes('ind');
        document.getElementById('demo').innerHTML = check;
    </script>
</body>
</html>

Hope this code will be helpful for you.

Happy Coding!

Answer