https://github.com/srph/droptake
:poop: Take values from an array from any starting position
https://github.com/srph/droptake
Last synced: about 1 month ago
JSON representation
:poop: Take values from an array from any starting position
- Host: GitHub
- URL: https://github.com/srph/droptake
- Owner: srph
- Created: 2016-01-05T10:42:25.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-01-07T14:33:32.000Z (over 10 years ago)
- Last Synced: 2025-01-26T17:15:52.802Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## droptake [](https://npmjs.org/package/droptake?style=flat-square) [](https://travis-ci.org/srph/droptake?branch=master)
```
npm i droptake -S
```
Take values from an array from any starting position
### Huh?
lodash vs droptake:
```diff
var arr = [1, 2, 3, 4, 5, 6];
- _.take(_.drop(arr, 2), 2);
+ droptake(arr, 2, 2);
```
Array.prototype.splice vs droptake:
```diff
- arr.splice(2, 4);
+ droptake(arr, 2, 2);
```
Nah, you really don't need this library.
### Usage
```js
var array = [1, 2, 3, 4, 5, 6];
droptake(array, 2, 2); // [3, 4]
```
You can leave out the last parameter which takes values starting from position 0 to n.
```
droptake(array, 2); // [1, 2]
```
### API
`droptake(array, n[, start]): Array`
- `array` (`Array`) - Array
- `n` (`Int`) - Number of values to take
- `start` (`Int`) - Starting position