Skip to the content.

$.fn.slice(start [, end])

Reduce the collection to a contiguous subset, mirroring Array.prototype.slice.

Signatures

slice(start: number, end?: number): this;

Parameters

Returns

A new Dabby collection containing the sliced elements in their original order.

Examples

import $ from "dabbyjs";
import "dabbyjs/traversal/slice/slice";

// First three list items
$("li").slice(0, 3);
import $ from "dabbyjs";
import "dabbyjs/traversal/slice/slice";

// Last two rows of a table
$("table tr").slice(-2);
import $ from "dabbyjs";
import "dabbyjs/traversal/slice/slice";

// Page 3 of a paged list (10 items per page)
$(".item").slice(20, 30);

See also