Array.prototype.first >= 0.1.2

Purpose

Return the first value of the array

Syntax

Array#first ( Numbernr Numberpage= 0 );


Parameters

nr
How many values should be returned
page
From what page they should be returned (The pagesize is the same as the nr of results to return)

Examples

Return the first value

This simply returns the first value, not contained inside an array. This can also be expressed using [0]

var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
arr.first();>>> 0

Explicitly setting the first value to 1 WILL return an array

var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
arr.first(1);>>> [0]

Return the first three values


var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
arr.first(3);>>> [0, 1, 2]

Return paged results

var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

arr.first(3, 1);>>> [3, 4, 5]

arr.first(3, 2);>>> [6, 7, 8]

Negative values

When nr is a negative value, all the values are returned except the absolute-of-nr last values.

var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

arr.first(-1);>>> [0, 1, 2, 3, 4, 5, 6, 7, 8];

arr.first(-3);>>> [0, 1, 2, 3, 4, 5, 6];