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
someArray.contains(value)
false
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.