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

Array.prototype.toSpliced() - 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.toSpliced()

Baseline Widely available

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

Array toSpliced() splice() . .

In this article

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

start

0 , ..

  • . start < 0 , start + array.length .
  • start < -array.length start , 0 .
  • start >= array.length , .
deleteCount Optional

start .

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

deleteCount 0 , . . ( ).

item1, , itemN Optional

start .

, toSpliced() .

start , item1, item2, , itemN start + deleteCount .

splice() toSpliced() . . . .

toSpliced() . undefined .

toSpliced() . this length .

,

toSpliced() , , slice() concat() .

js
const months = ["Jan", "Mar", "Apr", "May"];

//  1  
const months2 = months.toSpliced(1, 0, "Feb");
console.log(months2); // ["Jan", "Feb", "Mar", "Apr", "May"]

//  2 2  
const months3 = months2.toSpliced(2, 2);
console.log(months3); // ["Jan", "Feb", "May"]

//  1       
const months4 = months3.toSpliced(1, 1, "Feb", "Mar");
console.log(months4); // ["Jan", "Feb", "Mar", "May"]

//    
console.log(months); // ["Jan", "Mar", "Apr", "May"]

toSpliced()

toSpliced() .

js
const arr = [1, , 3, 4, , 6];
console.log(arr.toSpliced(1, 2)); // [1, 4, undefined, 6]

toSpliced()

toSpliced() this length . .

js
const arrayLike = {
  length: 3,
  unrelated: "foo",
  0: 5,
  2: 4,
};
console.log(Array.prototype.toSpliced.call(arrayLike, 0, 1, 2, 3));
// [2, 3, undefined, 4]

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


Web Proxy Viewer  |  New URL  |  Original Page