---
title: "How to shift and unshift using JavaScript?"  
description: "How to shift and unshift using JavaScript?"  
author: "Chris Anderson"  
published: 2011-10-17  
updated: 2020-09-16  
canonical: https://www.mindstick.com/interview/1296/how-to-shift-and-unshift-using-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# How to shift and unshift using JavaScript?

<script type="text/javascript">\
var numbers = ["one", "two", "three", "four"];\
numbers.unshift("zero");\
document.write(" "+numbers.shift());\
document.write(" "+numbers.shift());\
document.write(" "+numbers.shift());\
</script>\
This produces\
zero one two\
shift, unshift, push, and pop may be used on the same array. Queues are easily implemented using combinations.

## Answers

### Answer by Chris Anderson

<script type="text/javascript">\
var numbers = ["one", "two", "three", "four"];\
numbers.unshift("zero");\
document.write(" "+numbers.shift());\
document.write(" "+numbers.shift());\
document.write(" "+numbers.shift());\
</script>\
This produces\
zero one two\
shift, unshift, push, and pop may be used on the same array. Queues are easily implemented using combinations.


---

Original Source: https://www.mindstick.com/interview/1296/how-to-shift-and-unshift-using-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
