You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
528 B

4 years ago
  1. # `slice()`
  2. The slice method returns a slice of the collection starting at the given index:
  3. ```js
  4. const collection = collect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
  5. const slice = collection.slice(4);
  6. slice.all();
  7. // [5, 6, 7, 8, 9, 10]
  8. ```
  9. If you would like to limit the size of the returned slice, pass the desired size as the second argument to the method:
  10. ```js
  11. const slice = collection.slice(4, 2);
  12. slice.all();
  13. // [5, 6]
  14. ```
  15. [View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/slice.js)