The Parameters
The index at which to start changing the array. If greater than the length of the array, If negative, it will begin that many elements from the end of the array. (In this case, the origin deleteCount OptionalAn integer indicating the number of elements in the array to remove from
If If item1 , …, itemN OptionalThe elements to add to the array, beginning from If you do not specify any elements, Return valueAn array containing the deleted elements. If only one element is removed, an array of one element is returned. If no elements are removed, an empty array is returned. DescriptionIf the specified number of
elements to insert differs from the number of elements being removed, the array's ExamplesRemove 0 (zero) elements before index 2, and insert "drum"
Remove 0 (zero) elements before index 2, and insert "drum" and "guitar"
Remove 1 element at index 3
Remove 1 element at index 2, and insert "trumpet"
Remove 2 elements from index 0, and insert "parrot", "anemone" and "blue"
Remove 2 elements, starting from index 2
Remove 1 element from index -2
Remove all elements, starting from index 2
Specifications
Browser compatibilityBCD tables only load in the browser See also
Apa itu Splice di JavaScript?splice() merupakan method array di JavaScript yang berfungsi untuk mengubah elemen array termasuk menghapus, mengganti, atau menambah elemen baru. Method ini mengubah array asli dan mengembalikan array berisi elemen yang dihapus.
Apa itu array splice?Method Objek Array: Array.splice()
Method splice() adalah method 'serba-bisa' yang bisa digunakan untuk memotong array, menambahkan elemen array, bahkan melakukan keduanya sekaligus. Tidak seperti method slice() dan concat(), pemanggilan method ini akan mengubah array asal.
|