map()

Since: DataTables 1.10

Create a new API instance with the result set defined by the values returned from the callback function.

Description

The map() method is useful for traversing a result set and creating a new instance, whose result set is defined by the values returned. As such any logic condition can be applied to the values of the original result set, transforming the data as required.

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.

If you wish to remove items from the result set, use the filter() method.

This method is a proxy for the JavaScript Array.prototype.map 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 map. In browsers which do not support map natively, a polyfill is provided to allow this DataTables method to operate as expected.

Type

map( fn )

Iterate over the result set of an API instance, creating a new API instance from the values returned by the callback.

Parameters:

Returns:

DataTable.Api: New API instance with the values in the result set as those returned by the callback.

Example

Square the values from a column:

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

var squared = table
	.column(0)
	.data()
	.map(function (value, index) {
		return value * value;
	});