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




join() - FUNCTION


join() Function is used to join all the elements of the Array into a String.


Let us say, we have a Array that contains four names, Mohan, Kriti, Philip and Salim. And we want to convert the Array elements into a String.


Example :



<html>
<body>  
<script>

	var x = ["Mohan", "Kriti", "Philip", "Salim"]
	var y = x.join()
	document.write(y)    
    
</script>      
</body>
</html>


Output :



  Mohan,Kriti,Philip,Salim

So, we have an Array that has 4 names.

java_Collections

So, all we have done is, used the join() method to convert the elements of the array into a string.


var y = x.join()
java_Collections


Next, let us say we want to convert the array elements into a String. But we don't want the names separated by comma ','.


Rather, we want the names separated by @.


Example :



<html>
<body>  
<script>

	var x = ["Mohan", "Kriti", "Philip", "Salim"]
	var y = x.join("@")
	document.write(y)    
    
</script>      
</body>
</html>


Output :



  Mohan@Kriti@Philip@Salim

So, we have an Array that has 4 names.

java_Collections

So, all we have done is, used the join() method to convert the elements of the array into a string.


var y = x.join("@")
java_Collections