Skip to content
Subhajit Sahu edited this page Nov 20, 2022 · 15 revisions

Keep first n values only.

Alternatives: take, takeRight, takeWhile, takeWhileRight.
Similar: take, drop.


function take(x, n)
// x: an array
// n: number of values [1]
const array = require('extra-array');

var x = [1, 2, 3, 4, 5];
array.take(x, 2);
// → [ 1, 2 ]

array.take(x, 3);
// → [ 1, 2, 3 ]


References

Clone this wiki locally