Use of PUSH and POP in javascript?

Posted by

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