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




push() - FUNCTION


The push() Function is used to insert new values at the end of the Array.


Let us say, we have a Array that contains three names, Mohan, Kriti and Salim. And we want to insert a new name Nikhil at the last of the Array.


Example :



<html>
<body>  
<script>

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


Output :



  [Mohan,Kriti,Salim,Nikhil]

So, in the above code we have created a Array and initialised to the variable x.


var x = ["Mohan", "Kriti", "Salim"]

Below is how the values are positioned in the Array,

java_Collections

Then in the next line, we insert the element at the end of the Array.


x.push("Nikhil")
java_Collections


And we get the below output,


[Mohan,Kriti,Salim,Nikhil]