splice

Changes an ObservableArray by adding new items while removing old items. An equivalent of Array.prototype.splice.

The splice method raises the change event once or twice depending on the change. The action field of the event argument is set to "add" (if items are added) or "remove (if items are removed). The items field of the event argument is the array that contains the appended items or removed items. In the previous example, the change event will be triggered two times—the first one, because baseball is removed and, the second one, because tennis and hockey are added.

Returns

Array—Contains the removed items. The result of the splice method is not an instance of ObvservableArray.

Parameters

index Number

An index at which the changing of the array will start.

howMany Number

An integer which indicates the number of the items for removal. If set to 0, no items will be removed. In this case, you have to specify at least one new item.

item1, ..., itemN (optional)

The items that will be added to the array. If you do not specify any items, splice removes the items from the array.

Example - splice array items

<script>
var sports = new kendo.data.ObservableArray(["football", "basketball", "volleyball"]);
var removed = sports.splice(1, 1, "tennis", "hockey");
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(removed); // outputs ["basketball"]
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(sports); // outputs ["football", "tennis", "hockey", "volleyball"]
</script>
In this article