// Create an Array
const fruits = ["Banana", "Orange", "Apple", "Mango"];
// At position 2, add "Lemon" and "Kiwi":
const fruits2 = fruits.toSpliced(2, 0, "Lemon", "Kiwi");
Try it Yourself »More Examples Below !
DescriptionThe toSpliced()
method adds and/or removes array elements.
The toSpliced()
method returns a new array.
The toSpliced()
method does not change the original array.
The toSpliced()
method is the copying version of the splice()
method.
array.toSpliced(index, count, item1, ....., itemX)
Parameters Parameter Description index Required.// Create an Array
const fruits = ["Banana", "Orange", "Apple", "Mango"];
// At position 2, remove 2 items
const fruits2 = fruits.toSpliced(2, 2);
Try it Yourself » Example// Create an Array
const fruits = ["Banana", "Orange", "Apple", "Mango"];
// At position 2, remove 1 item, add "Lemon" and "Kiwi"
const fruits2 = fruits.toSpliced(2, 1, "Lemon", "Kiwi");
Try it Yourself » Browser SupporttoSpliced()
is a JavaScript 2023 feature.
ES 2023 is supported in all modern browsers since July 2023:
ChromeTrack your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4