ArrayAppend

Append a value to an array

Method Signature

ArrayAppend(array=[modifiableArray], value=[any], merge=[boolean])

Arguments

Argument
Type
Required
Description
Default

array

modifiableArray

true

The array to which the element should be appended.

value

any

true

The element to append. Can be any type.

merge

boolean

false

If true, the value is assumed to be an array and the elements of the array are appended to the array. If false, the value is appended as a single element.

false

Examples

Append a value to an array

Uses the arrayAppend function to append a value to the end of the array

Run Example

someArray = [ 
	1,
	2,
	3
];
arrayAppend( someArray, 4 );
writeOutput( JSONSerialize( someArray ) );

Result: [1,2,3,4]

Append a value to an array using the Array member function

Invoking the append function on an array is the same as running arrayAppend.

Run Example

someArray = [ 
	1,
	2,
	3
];
someArray.append( 4 );
writeOutput( JSONSerialize( someArray ) );

Result: [1,2,3,4]

Append more than one item

You can merge two arrays when third parameter is set to true.

Run Example

someArray = [ 
	1,
	2,
	3
];
ArrayAppend( someArray, [
	4,
	5,
	6
], true );
writeDump( JSONSerialize( someArray ) );

Result: [1,2,3,4,5,6]

Additional Examples

Run Example

numbers = [ 
	1,
	2,
	3,
	4
];
ArrayAppend( numbers, 5 );
Dump( numbers ); // Outputs [ 1, 2, 3, 4, 5 ]
numbers = [
	1,
	2,
	3,
	4
];
moreNumbers = [
	5,
	6,
	7,
	8
];
ArrayAppend( numbers, moreNumbers );
Dump( numbers ); // Outputs [ 1, 2, 3, 4, [ 5, 6, 7, 8 ] ]
numbers = [
	1,
	2,
	3,
	4
];
moreNumbers = [
	5,
	6,
	7,
	8
];
ArrayAppend( numbers, moreNumbers, true );
Dump( numbers );
 // Outputs [ 1, 2, 3, 4, 5, 6, 7, 8 ]

Last updated

Was this helpful?