in_array()

Function to check whether a given value (needle) exists in an array (haystack).

The function in_array() is located in the file array.jsxinc.

Usage

To check whether the value exists:

var value = "c";
var array = new Array("a", "b", "c", "d");
if(in_array(value, array))
   //Do something if the value is in the array

To check whether the value exits and that the value is the same data type:

var value = "c";
var array = new Array("a", "b", "c", "d");
if(in_array(value, array, true))
   //Do something if the value is in the array

Parameters

Parameter Data type Required Description
needle String Yes The value you want to check.
haystack Array Yes The array to search the value.
strict Boolean   Set to true if the function needs to match the data type as well as the value. Default is false.

Return values

Value Meaning
true The value is in the array.
false The value is not in the array.