arrayContains

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

arrayContains(array, object) → returns boolean

Member Function Syntax

someArray.contains(object)

arrayContains Argument Reference

array array
Required

The array in which to search.

object any
Required

The object 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


Array Contains

CF 9+

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

Expected Result: true


Array Contains (member function)

CF 10+

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

Expected Result: true


Array Contains

Lucee 4.5+

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

Expected Result: 2


Array Contains (member function)

Lucee 4.5+

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

Expected Result: 2


Substring Search

Lucee 4.5+

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

Expected Result: 1


Fork me on GitHub