arrayIndexExists

Returns whether there exists an item in the array at the selected index.

arrayIndexExists(array, index) → returns boolean

Member Function Syntax

array.indexExists(index)

This function requires Lucee. Not supported on Adobe ColdFusion.

arrayIndexExists Argument Reference

array
Required

index
Required

Examples sample code invoking the arrayIndexExists function


Standard function call when checking for an existing element

In this example, the index we are checking exists in the array so the check returns true.

myArray=[];
myArray[1]='one';
myArray[2]='two';
myArray[3]='three';
myArray[4]='four';
myArray[5]='five';
result = arrayIndexExists(myArray, 3);
writeOutput(result);

Expected Result: true


Standard function call when checking for a nonexisting element

In this example, there is no element at the index we're checking so the check returns false.

myArray=[];
myArray[1]='one';
myArray[2]='two';
// no element at index 3
myArray[4]='four';
myArray[5]='five';
result = arrayIndexExists(myArray, 3);
writeOutput(result);

Expected Result: false


Standard function call when checking an empty array

In this example, the array we are searching is empty so the check returns false.

myArray=[];
result = arrayIndexExists(myArray, 3);
writeOutput(result);

Expected Result: false


Member function syntax

In this example, the index we are checking exists in the array so the check returns true.

myArray=[];
myArray[1]='one';
myArray[2]='two';
myArray[3]='three';
myArray[4]='four';
myArray[5]='five';
result = myArray.indexExists(3);
writeOutput(result);

Expected Result: true


Fork me on GitHub