{hero}

indexOf()

Since: DataTables 1.10

Find the first instance of a value in the API instance's result set.

Description

It is often very useful to know if a value is in a result set, and further, what its position is in the result set if it is present. This method provides exactly that ability, searching for the value given, starting from index 0 (see lastIndexOf() for starting at the end of the array) and giving its position in the result set.

This method makes use of the fact that DataTables API objects are "array like", in that they inherit a lot of the abilities and methods of the Javascript Array type.

In this case, this method is a proxy for the Javascript Array.prototype.indexOf method and is provided as a utility method for the DataTables API. For more information about the original method, please refer to the Mozilla MDN documentation for indexOf. In browsers which do not support indexOf natively, a polyfill is provided to allow this DataTables method to operate as expected.

Type

function indexOf( value )

Description:

Find the first instance of a value in the API instance's result set.

Parameters:
Returns:

The index of the item in the result set, or -1 if not found.

Example

Find an item in a column of data:

var table = new DataTable('#myTable');

var index = table
	.column(0)
	.data()
	.indexOf(21);

if (index < 0) {
	alert('21 was not found in the result set');
}
else {
	alert('21 was found at index: ' + index);
}

Related

The following options are directly related and may also be useful in your application development.