Modifies an array by removing elements and adding new elements. It starts from the index, removes as many elements as specified by elementCountForRemoval, and puts the replacements starting from index position.
arraySplice(array, index[, elementCountForRemoval, replacements])
returns array
someArray.splice(index[, elementCountForRemoval, replacements])
Name | Type | Required | Default | Description |
---|---|---|---|---|
array | array | Yes | The array to splice and modify. | |
index | numeric | Yes | The position at which to start modifying the array. If the position is greater than the length of the array, the replacement elements will be inserted after the last array element. If the position is less than 0, the start is set to the end of the array and the origin is set accordingly. | |
elementCountForRemoval | numeric | No | The number of elements to be removed starting with the start index. | |
replacements | array | No | Array of elements to be added to the array starting with index start. |
months = ['Jan', 'March', 'April', 'June'];
item = ["Feb"];
arraySplice( months, 2, 0, item );
writedump(months);
months = ['Jan', 'March', 'April', 'June'];
item = ["Feb"];
arraySplice( months, 3, 2, item );
writedump(months);
months = ['Jan', 'March', 'April', 'June'];
item = ["Feb"];
arraySplice( months, -3, 0, item );
writedump(months);
months = ['Jan', 'March', 'April', 'June'];
item = ["Feb"];
arraySplice( months, 5, 0, item );
writedump(months);
months = ['Jan', 'March', 'April', 'June'];
item = ["Feb"];
months.splice( 2, 0, item );
writedump(months);