ArraySlice

Extracts a sub array from an existing array.

Method Signature

ArraySlice(array=[array], start=[integer], length=[integer])

Arguments

Argument
Type
Required
Description
Default

array

array

true

start

integer

true

1

length

integer

false

0

Examples

Simple arraySlice Example

Run Example

array = [ 
	1,
	2,
	3,
	4,
	5,
	6,
	7,
	8
];
newArray = arraySlice( array, 2, 3 );
writedump( newArray );

Result: [2,3,4]

arraySlice with no length specified

Run Example

array = [ 
	1,
	2,
	3,
	4,
	5,
	6,
	7,
	8
];
newArray = arraySlice( array, 4 );
writedump( newArray );

Result: [4,5,6,7,8]

arraySlice using a negative offset

Run Example

array = [ 
	1,
	2,
	3,
	4,
	5,
	6,
	7,
	8
];
newArray = arraySlice( array, -5, 3 );
writedump( newArray );

Result: [4,5,6]

Slice an array using member function

CF11+ calling the slice member function on an array.

Run Example

array = [ 
	1,
	2,
	3,
	4,
	5,
	6,
	7,
	8
];
newArray = array.slice( 2, 3 );
writedump( newArray );

Result: [2,3,4]

Additional Examples

Run Example

newArray = [ 
	"a",
	"b",
	"c",
	"b",
	"d",
	"b",
	"e",
	"f"
];
dump( newArray );
hasSome1 = arraySlice( newArray, 1, 4 );
dump( hasSome1 );
// member function
hasSome2 = newArray.slice( 3, 6 );
dump( hasSome2 );

Last updated

Was this helpful?