Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




includes() - FUNCTION


includes() Function


The includes() Function is search for the substring and returns true if it is present and false if not.


Example :



<html>
<body>  
<script>

	var x = "Hello Beautiful World"
	var y = x.includes("Beautiful")
	if (y == true) {
		document.write("The substring Beautiful is present in the String")
	}
	else {
		document.write("The substring Beautiful is not present in the String")	
	}
    
</script>      
</body>
</html>


Output :



  The substring Beautiful is present in the String

In the above code, we have declared a String Hello Beautiful World and assigned it to a variable x.


x = "Hello Beautiful World"
java_Collections


And we would be searching the substring Beautiful, from the String, Hello Beautiful World.


So, we have used the includes() Function to search the substring Beautiful.


y = x.includes("Beautiful")

And what includes() Function does is, goes to the String Hello Beautiful World and searches for the substring Beautiful.

java_Collections

And finds the substring Beautiful in the 6th position.


So it returns true.


And the if statement finds a match.


if (y == true) {
	document.write("The substring Beautiful is present in the String")
}
else {
	document.write("The substring Beautiful is not present in the String")
}