Why Collect.js ?
npm install collect-js
Using CDN Link: We can use CDN Link to run the code instead of installing it. Go to https://cdnjs.com/libraries/collect.js and add the following CDN link inside the head section.
<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>
Example: In this example, we will get the array or object represented by the collection using all() method.
const collect = require('collect.js'); let arr = [1, 2, 3] // Convert array into collection const collection = collect(arr); // Returning the array let newObject = collection.all(); console.log("Result : ", newObject);
Result : [1, 2, 3]
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above