ArraySplice

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.

Method Signature

ArraySplice(array=[modifiablearray], index=[Integer], elementCountForRemoval=[Integer], replacements=[array])

Arguments

Argument
Type
Required
Description
Default

array

modifiablearray

true

The array to splice

index

Integer

true

The initial position to remove or insert from

elementCountForRemoval

Integer

false

The number of elemetns to remove

0

replacements

array

false

An array of elements to insert

Examples

arraySplice inserting replacements at position 2 while removing 0 elements

Run Example

months = [ 
	"Jan",
	"March",
	"April",
	"June"
];
item = [
	"Feb"
];
arraySplice( months, 2, 0, item );
writedump( months );

Result: ["Jan","Feb","March","April","June"]

arraySplice inserting replacements at position 3 while removing 2 elements

Run Example

months = [ 
	"Jan",
	"March",
	"April",
	"June"
];
item = [
	"Feb"
];
arraySplice( months, 3, 2, item );
writedump( months );

Result: ["Jan","March","Feb"]

arraySplice inserting replacements at position -3 while removing 0 elements

Run Example

months = [ 
	"Jan",
	"March",
	"April",
	"June"
];
item = [
	"Feb"
];
arraySplice( months, -3, 0, item );
writedump( months );

Result: ["Jan","Feb","March","April","June"]

arraySplice inserting replacements at position 5 which is greater than the length of the array

Run Example

months = [ 
	"Jan",
	"March",
	"April",
	"June"
];
item = [
	"Feb"
];
arraySplice( months, 5, 0, item );
writedump( months );

Result: ["Jan","March","April","June","Feb"]

Splice an array using member function

Run Example

months = [ 
	"Jan",
	"March",
	"April",
	"June"
];
item = [
	"Feb"
];
months.splice( 2, 0, item );
writedump( months );

Result: ["Jan","Feb","March","April","June"]

Additional Examples

Run Example

Days = [ 
	"Sun",
	"Mon",
	"Wed",
	"Thurs",
	"Fri",
	"Sat"
];
item = [
	"Tues"
];
ArraySplice( Days, 3, 0, item );
writedump( Days );

Last updated

Was this helpful?