[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array/splice [Back]  [Original]

Array.prototype.splice() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Array.prototype.splice()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

splice() , / .

In this article

js
splice(start)
splice(start, deleteCount)
splice(start, deleteCount, item1)
splice(start, deleteCount, item1, item2)
splice(start, deleteCount, item1, item2, /* , */ itemN)

start

, ( ), .

  • : -array.length <= start < 0, start + array.length.
  • start < -array.length, 0.
  • start >= array.length, , , .
  • start ( splice() ), . undefined, 0.
deleteCount

, , , start.

deleteCount , start, start . itemN, Infinity deleteCount, start, undefined 0.

deleteCount 0 , . (. ).

item1, , itemN

, , start.

, splice() .

, . , . , .

, .

0 2 "drum"

js
var myFish = ["angel", "clown", "mandarin", "sturgeon"];
var removed = myFish.splice(2, 0, "drum");

// myFish  ["angel", "clown", "drum", "mandarin", "sturgeon"]
// removed  [],   

1 3

js
var myFish = ["angel", "clown", "drum", "mandarin", "sturgeon"];
var removed = myFish.splice(3, 1);

// removed  ["mandarin"]
// myFish  ["angel", "clown", "drum", "sturgeon"]

1 2 "trumpet"

js
var myFish = ["angel", "clown", "drum", "sturgeon"];
var removed = myFish.splice(2, 1, "trumpet");

// myFish  ["angel", "clown", "trumpet", "sturgeon"]
// removed  ["drum"]

2 0 "parrot", "anemone" "blue"

js
var myFish = ["angel", "clown", "trumpet", "sturgeon"];
var removed = myFish.splice(0, 2, "parrot", "anemone", "blue");

// myFish  ["parrot", "anemone", "blue", "trumpet", "sturgeon"]
// removed  ["angel", "clown"]

2 2

js
var myFish = ["parrot", "anemone", "blue", "trumpet", "sturgeon"];
var removed = myFish.splice(myFish.length - 3, 2);

// myFish  ["parrot", "anemone", "sturgeon"]
// removed  ["blue", "trumpet"]

1 -2

js
var myFish = ["angel", "clown", "mandarin", "sturgeon"];
var removed = myFish.splice(-2, 1);

// myFish  ["angel", "clown", "sturgeon"]
// removed  s ["mandarin"]

2 ()

js
var myFish = ["angel", "clown", "mandarin", "sturgeon"];
var removed = myFish.splice(2);

// myFish  ["angel", "clown"]
// removed  ["mandarin", "sturgeon"]

Specification
ECMAScript 2027 LanguageSpecification
# sec-array.prototype.splice

JavaScript 1.2 splice() ( deleteCount 1); . , , JavaScript 1.2, Netscape Navigator 4, , splice() .


Web Proxy Viewer  |  New URL  |  Original Page