arrayMerge

arrayMerge(array1, array2 [, leaveIndex]) → returns array

Member Function Syntax

array1.merge(array2 [, leaveIndex])

This function requires Lucee. Not supported on Adobe ColdFusion.

Argument Reference for the arrayMerge function

array1

Required: Yes

array2

Required: Yes

leaveIndex

Required: No

Examples sample code invoking the arrayMerge function


Standard function syntax

Lucee 4.5+ Merge two arrays resulting in a single re-indexed array. All elements of both arrays are preserved.

fruit = ['apple','banana','orange'];
veggies = ['tomato','carrot','corn','peas','peppers'];
healthyFoods = arrayMerge(fruit, veggies);
writeOutput(arrayToList(healthyFoods));

Expected Result: apple,banana,orange,tomato,carrot,corn,peas,peppers


Member function syntax

Lucee 4.5+ Merge two arrays resulting in a single re-indexed array. All elements of both arrays are preserved.

fruit = ['apple','banana','orange'];
veggies = ['tomato','carrot','corn','peas','peppers'];
healthyFoods = fruit.merge(veggies);
writeOutput(arrayToList(healthyFoods));

Expected Result: apple,banana,orange,tomato,carrot,corn,peas,peppers


Example where leaveIndex parameter is true

Lucee 4.5+ Merge two arrays resulting in a single re-indexed array. Where the both arrays have elements in the same position, only values from the first array are included in the result. Valid using standard or member function syntax.

Note how the first three elements of the veggies array are not merged because the fruit array already has values for elements 1-3.

fruit = ['apple','banana','orange'];
veggies = ['tomato','carrot','corn','peas','peppers'];
healthyFoods = arrayMerge(fruit, veggies, true);
writeOutput(arrayToList(healthyFoods));

Expected Result: apple,banana,orange,peas,peppers


Fork me on GitHub