C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Array includes() methodThe JavaScript array includes() method checks whether the given array contains the specified element. It returns true if an array contains the element, otherwise false. SyntaxThe includes() method is represented by the following syntax: array.includes(element,start) Parameterelement - The value to be searched. start - It is optional. It represents the index from where the method starts search. ReturnA Boolean value. JavaScript Array includes() method exampleHere, we will understand includes() method through various examples. Example 1Let's see a simple example to determine whether the given array contains the specified element. <script> var arr=["AngularJS","Node.js","JQuery"] var result=arr.includes("AngularJS"); document.writeln(result); </script> Output: true Example 2In this example, we will provide the index from where the search starts. <script> var arr=["AngularJS","Node.js","JQuery"] var result=arr.includes("AngularJS",1); //returns false, as "AngularJS" is not present after index 1. document.writeln(result); </script> Output: false Example 3Let's see one more example to determine whether the includes() method is case-sensitive. <script> var arr=["AngularJS","Node.js","JQuery"] var result=arr.includes("angularjs"); document.writeln(result); </script> Output: false
Next TopicJavaScript Array
|