{hero}

lastIndexOf()

Since: DataTables 1.10

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

Description

It is often useful to know if a value is in a result set, and if so, which position it holds. This method provides exactly that ability, searching for the value given, starting from the last item in the instance's result set and working back through the result set (see indexOf() to search for the first instance of a value) 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.lastIndexOf 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 lastIndexOf. In browsers which do not support lastIndexOf natively, a polyfill is provided to allow this DataTables method to operate as expected.

Type

function lastIndexOf( value )

Description:

Find the last 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 the last index of an item in a column of data:

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

var index = table
	.column(0)
	.data()
	.lastIndexOf(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.