VOOZH about

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

⇱ Collect.js Introduction - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js Introduction

Last Updated : 23 Jul, 2025

Collect.js is a JavaScript library for collecting data from tree-based structures. This library is used on JavaScript Array and Objects.

Features: Some of the important features of Collect.js are:

  • It is a fluent and convenient wrapper for working with arrays and objects.
  • It provides us with different functions that help in working with data much easier.
  • It also helps the programmers to write more concise code and easier to maintain the JavaScript code.
  • It is also compatible with Laravel.

Installation: We can install collect.js by following two methods.

Method 1: We can install it using npm. Make sure that you have Node.js and npm installed.

npm install collect-js

Method 2: We can also use it through CDN Links. Go to the https://cdnjs.com/libraries/collect.js and add the following CDN link inside <script> tag.

<script src="https://cdnjs.cloudflare.com/ajax/libs/collect.js/4.29.3/collect.min.js" integrity=
"sha512eHrXl+YqedGIdIKP5YOueP0z7RfRgmo7R1d8pTvEOhikZIFpD54dXbwp9os9z4hVHVHZeRHw0qfF93lDsQDQA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

Lets's see an example of how collect.js works.

Example: In this example, we will see how to create new collection instance using Collect.js make() Function.

Run the index.js file using the following command:

node index.js

Output:

[ 1, 2, 3, 4, 5 ]
[ 1, 2, 3 ]
Comment
Article Tags: