arrayContains

Used to determine if a value is in the given array, case-sensitive. Adobe CF and OpenBD return boolean. Lucee / Railo returns the numeric index if the value is found, 0 if not.

arrayContains(array, value) → returns boolean

Member Function Syntax

someArray.contains(value)

Argument Reference

array array
Required

The array in which to search.

value any
Required

The value to search for in the array.

substringMatch any
Default: false

Lucee 4.5+ If set to true then a substring match will also return an array position. This will only work with simple values. Passing true with complex objects will throw an exception.

Compatibility

Lucee:

Returns the position of the array instead of boolean value.

Examples
Sample code invoking the arrayContains function

CF 9+

someArray = [1,2,3];
writeDump(arrayContains(someArray,2));

Expected Result: true

CF 10+

someArray = [1,2,3];
writeDump(someArray.contains(2));

Expected Result: true

Lucee 4.5+

someArray = [1,2,3];
writeDump(arrayContains(someArray,2));

Expected Result: 2

Lucee 4.5+

someArray = [1,2,3];
writeDump(someArray.contains(2));

Expected Result: 2

Lucee 4.5+

words = [ 'hello' , 'world' ];
positionOfSubstring = arrayContains( words, 'el', true );
writeDump(positionOfSubstring);

Expected Result: 1

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub