JavaScript Array pop() Definition
The pop () method removes the last element of an array. And define a new array. So this method changes the sequence (length and elements).
pop () does not perform properly when applied regularly to non-sequence arrays. If we apply pop () in an empty array, it returns the “undefined” value.
Syntax:
array.pop()
JavaScript Array pop() Examples
Example 1
let animal = ["cat", "dog", "horse", "donkey"];
console.log(animal.pop())
output:
donkey
Example 2
let numbers = ["first", "second", "third"];
let third = numbers.pop();
console.log(third)
let second = numbers.pop();
console.log(second)
let first = numbers.pop();
console.log(first)
output:
third
second
first
Example 3
let alphabet = ["a", "b", "c", "d"];
var newList = alphabet.pop();
console.log(alphabet);
console.log(newList);
output:
[“a”, “b”, “c”]
d
Browser Support
| Chrome | 1 |
| Edge | yes |
| Firefox | 1 |
| Internet Explorer | 5.5 |
| Opera | yes |
| Safari | yes |
| Android webview | yes |
| Chrome for Android | yes |
| Edge mobile | yes |
| Firefox for Android | 4 |
| Opera Android | yes |