HOWTO · JavaScript

How to Remove First Element From an Array in JavaScript

Learn how to remove the first item from a JavaScript array with mutating and nonmutating methods, and choose the right return value.

On this page

To remove the first element from a JavaScript array, use shift() or splice(0, 1) to change the original array. If you need to keep the original, use slice(1) or filter() to create a new array. shift() returns the removed item as a single value, while splice(0, 1) returns it in an array.

Remove the first element by mutating the array

Both shift() and splice() remove an item from the original array. Choose shift() when you always want the first item; choose splice() when you want the same operation to work at a specified index or to remove several items.

shift() removes the element at index 0, moves the remaining elements toward the beginning, and returns the removed value. Run this example to see the updated array and returned item:

const items = ["first", "second", "third"];
const removed = items.shift();
console.log(JSON.stringify({ items, removed }));
{"items":["second","third"],"removed":"first"}

After these statements, items contains the last two strings, and removed contains "first". JSON.stringify() makes the printed object a single JSON line in a JavaScript runtime.

Use splice(start, deleteCount) when you need to choose the position. To remove the first item, pass 0 as start and 1 as deleteCount. The original array is modified, and the method returns an array containing the removed elements. For example, with const values = ["red", "green", "blue"], const removed = values.splice(0, 1) leaves values as ["green", "blue"] and sets removed to ["red"].

The start argument identifies an index; it does not set a direction of travel. A nonnegative index counts from the beginning, while a negative index counts backward from the end (-1 refers to the last element). deleteCount specifies how many items to remove from that position. If you omit it, splice() removes all elements from start onward. Items supplied after deleteCount are inserted at that position. For the method’s full parameter behavior, see the MDN splice() reference.

Remove the first element without mutating the array

slice() and filter() return new arrays and leave the input array unchanged. Use slice(1) for the direct operation of copying every item after the first. The start index is included, and an optional end index is excluded. Thus, values.slice(1) copies from index 1 through the end; it does not remove anything from values. See the slice() guide and the MDN slice() reference for more details.

Use filter() when removal depends on a condition. Its callback runs for each item, and items for which the callback returns true are included in a new array. To skip only the first position, filter by index:

const remaining = values.filter((item, index) => index > 0);

This keeps later items in their existing order and preserves values. Filtering by index expresses a positional rule; if the array has already been reordered, it still excludes the item at position 0, whatever its value is.

For example, with const values = ["red", "green", "blue"], either values.slice(1) or values.filter((item, index) => index > 0) produces a new array containing ["green", "blue"], while values remains ["red", "green", "blue"].

Choose the method that matches your array needs

  • Use shift() when the original array should change and you need the removed item as a single value.
  • Use splice(0, 1) when the original should change and an array of removed items is useful, or adapt the index and count to remove elsewhere.
  • Use slice(1) when you want a new array containing everything after the first item.
  • Use filter() when the items to keep are determined by a condition; an index condition is enough to omit the first position.

The key choice is whether other code still needs the original array. The mutating methods update that shared array, so any references to it observe the change. The nonmutating methods leave that array available and return a separate result. All four methods preserve the relative order of the elements they keep.