
Var arr=Įxplanation: The above script starts looking for the word ‘will’ in the array from position 2. Let us run and see the results of the below code. We will now change the word to be searched to ‘will’. The result which is displayed is hence true. If you check the above screenshot the result of the above code snippet is true as the includes() method finds 2 in the array. The third statement work for this purpose. True will signify that the mentioned element is present in the array and false will signify that it is not present in the array. Post find the result we can print it and get it if it is true or false. The second statement here serves this purpose.

Once this array is created it makes use of the includes() method to check if 2 is there in the mentioned array. Examples to Implement JavaScript Array includes()īelow are the examples mentioned: Example #1 – Numeric arrayĮxplanation: The above script first creates an array. If the element is found then it will have to return true or the function will return false. It will look for the number or element from the index position mentioned and traverse the array until the end. If the optional parameter with start position was mentioned then instead of traversing the entire array the method includes() would have started from that position. It will return the value true and this will be stored in the user-defined variable checkInclude. It traverses through the array and looks for the integer 2 in it. That means it will directly start looking for 2 in the array A. It will check if the array contains for the integer 2. This variable is used to store the result of the include() method. Here in this statement a checkInclude variable is used.
