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.
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
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.
Related links
Powered by web-features