- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The shift method removes the element at the zeroeth index and shifts the values at consecutive indexes down, then returns the removed value. If the length property is 0, undefined is returned.
The pop() method removes the last element from an array and returns that element. This method changes the length of the array.
let fruits = ['apple', 'mango', 'orange', 'kiwi']; let fruits2 = ['apple', 'mango', 'orange', 'kiwi']; console.log(fruits.pop()) console.log(fruits2.shift()) console.log(fruits) console.log(fruits2)
kiwi apple [ 'apple', 'mango', 'orange' ] [ 'mango', 'orange', 'kiwi' ]
Note that both the original arrays were changed here.
Shift is slower than pop because it also needs to shift all the elements to the left once the first element is removed.
- Difference between OOP and POP
- Difference between Constructors and Methods in Java
- Difference between find() and findOne() methods in MongoDB?
- Difference between BeforeClass and BeforeTest methods in TestNG
- Difference between the list() and listFiles() methods in Java
- Difference between title() and wm_title() methods in Tkinter class
- What is the difference between del, remove and pop on lists in python ?
- What is the difference between non-static methods and abstract methods in Java?