VOOZH about

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

⇱ Collect.js takeWhile() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js takeWhile() Method

Last Updated : 3 Dec, 2020

The takeWhile() method is used to return the items in the collection until the given callback returns false. If the callback never returns false, the takeWhile() method will return all items in the collection.

Syntax:

collect.takewhile()

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

Return Value: This method returns the items in the collection.

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 takeWhile() method in collect.js:

Example 1: Filename: index.js

Run the index.js file using the following command:

node index.js

Output:

[1, 2, 3, 4, 5, 6]

Example 2: Filename: index.js

Run the index.js file using the following command:

node index.js

Output:

[2, 4, 5, 6, 7, 8, 9]
Comment
Article Tags: