VOOZH about

URL: https://www.geeksforgeeks.org/javascript/collect-js-take-method/

⇱ Collect.js take() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js take() Method

Last Updated : 3 Dec, 2020

The take() method is used to return a new collection with the specified number of items. It returns the elements from the end of the collection if the argument passed as a parameter is negative.

Syntax:

collect.take()

Parameters: The collect() method takes one argument that is converted into the collection and then the take() method is applied to it.

Return Value: This method returns a new collection with the specified number of items.

Module Installation: Install collect.js module using the following command from the root directory of your project:

npm install collect.js

The below example illustrates the take() method in collect.js:

Example 1: Filename: index.js

Run the index.js file using the following command:

node index.js

Output:

[2, 4, 5, 6, 7]

Example 2: Filename: index.js

Run the index.js file using the following command:

node index.js

Output:

[4, -6, 7]
Comment
Article Tags: