The pop() method removes (pops) the last element of an array.
The pop() method changes the original array.
The pop() method returns the removed element.
array.pop()???????
None
Type |
Description |
A variable |
The removed item. |
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
var a = ["Sanjay", "Aman", "Rehman", "Karan"];
document.write(a + "<br><br>");
a.pop();
document.write(a);
</script>
</head>
<body>
</body>
</html>
The push() method adds new items to the end of an array.
The push() method changes the length of the array.
The push() method returns the new length.
array.push(item1, item2, ..., itemX)
Parameters |
Description |
item1 |
The item(s) to add to the array. |
Type |
Description |
A number |
The new length of the array. |
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
var a = ["Sanjay", "Aman", "Rehman"];
a.push("Rahul");
document.write(a + "<br><br>");
a.push("Salman");
document.write(a + "<br><br>");
</script>
</head>
<body>
</body>
</html>