Widely availableSupported across all major browsers. Safe to use in production.

Overview

The array splice() method changes an array in-place. You can use it to delete items, overwrite items, or insert items, starting from an index.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
1
12
1
1
18
1
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

JAVASCRIPT
const arr = ['a', 'b', 'c', 'd'];

// Remove
arr.splice(1, 2); // Return value: ['b', 'c'], arr: ['a', 'd']

// Insertion
arr.splice(1, 0, 'x', 'y'); // arr: ['a', 'x', 'y', 'd']

// Replacement
arr.splice(1, 1, 'z'); // arr: ['a', 'z', 'y', 'd']

Live demo

Element. Delete

specifiedposition from specific. countonlyelement getexclude..

PreviewFullscreen

Element. insert

Deletecount 0 to and in, specific. to element difference only..

PreviewFullscreen

Element. replace

Delete and insert simultaneous to row, element put..

PreviewFullscreen

Use cases

  • Using Array splice()

    The array splice() method changes an array in-place. You can use it to delete items, overwrite items, or insert items, starting from an index.

Cautions

  • No specific concerns. Stable across all major browsers.

Accessibility

  • When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.

Powered by web-features