.pop() method does two things:
Let's dive into some code examples to understand the
.pop() method better:
As you can see in the example, the
.pop() method removes the last element 'orange' from the
fruits array and returns it as the result. The
fruits array now contains only 'apple' and 'banana'.
It's important to note that the
.pop() method permanently modifies the original array. If you want to keep the removed element, you should save it in a separate variable, as shown in the example.
Declare a variable called
removedFruit and assign it the value of using the
.pop() method on the
removedFruit variable to the console.
Sign up to start coding
Already have an account?