Use of PUSH and POP in javascript?

Posted by

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOps School!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

PUSH and POP is used to perform insertions as well as deletions from the object. array_push is used to add value in the array(it always add new value at the last place) and array_pop is used to remove last value from the array.

POP() syntax

array.pop()

PUSH() syntax

array.push(item1, item2, ..., itemX)

example

<!DOCTYPE html>
<html>
<head>
		<title> alert in javascript</title>
</head>
<body>
		<script>
		var array = ["sam","ramu","array","string","function"];
		
		document.write(array + "<br><br>");
		
		array.pop("function");
		
		document.write(array + "<br><br>");
		
		array.push("salman");
		
		document.write(array + "<br><br>");
		
		</script>

</body>
</html>

output

sam,ramu,array,string,function

sam,ramu,array,string

sam,ramu,array,string,salman
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x