@extra-array/take
Version:
Keeps first n values only.
53 lines (39 loc) • 1.61 kB
Markdown
Keeps first n values only.
[:package:](https://www.npmjs.com/package/@extra-array/take)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/take)
[:vhs:](https://asciinema.org/a/332145)
[:moon:](https://www.npmjs.com/package/@extra-array/take.min)
[:scroll:](https://unpkg.com/@extra-array/take/)
[:newspaper:](https://nodef.github.io/extra-array/)
[:blue_book:](https://github.com/nodef/extra-array/wiki/)
> Alternatives: [take], [takeRight], [takeWhile], [takeWhileRight].<br>
> Similar: [take], [drop].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
<br>
```javascript
array.take(x, [n]);
// x: an array
// n: number of values (1)
```
```javascript
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 ]
```
<br>
<br>
## References
- [Data.List.take: Haskell](https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-List.html#v:take)
- [Array.prototype.slice: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
- [_.take: lodash](https://lodash.com/docs/4.17.15#take)
- [Array.to: sugarjs](https://sugarjs.com/docs/#/Array/to)
[take]: https://github.com/nodef/extra-array/wiki/take
[takeWhile]: https://github.com/nodef/extra-array/wiki/takeWhile
[drop]: https://github.com/nodef/extra-array/wiki/drop
[takeRight]: https://github.com/nodef/extra-array/wiki/takeRight
[takeWhileRight]: https://github.com/nodef/extra-array/wiki/takeWhileRight