limitTo Filter
Description
Creates a new array or string containing only a specified number of elements.
The elements are taken from either the beginning or the end of the source array,
string, or number, as specified by the value and sign (positive or negative) of
limit. Other array-like objects are also supported (e.g., array subclasses,
NodeLists, JQLite/jQuery collections, etc.). If a number is used as input, it is
converted to a string.
Parameters
- input
{Array|ArrayLike|string|number}: Array/array-like, string, or number to be limited. - limit
{string|number}: The length of the returned array or string.- If the
limitnumber is positive,limitnumber of items from the beginning of the source array/string are copied. - If the number is negative,
limitnumber of items from the end of the source array/string are copied. - The
limitwill be trimmed if it exceedsarray.length. - If
limitis undefined, the input will be returned unchanged.
- If the
- begin
{(string|number)=}: Index at which to begin limitation. As a negative index,beginindicates an offset from the end ofinput. Defaults to0.
Returns
{Array|string}: A new sub-array or substring of lengthlimitor less if the input had less thanlimitelements.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.