
Bring Laravel Collections to JavaScript with Collect.js
Collect.js is a port of Laravel Collections to JavaScript. It’s dependency free and makes working with arrays and objects easy.
Here is an example of utilizing the where
method:
const collection = collect([
{'product': 'Desk', 'price': 200},
{'product': 'Chair', 'price': 100},
{'product': 'Bookcase', 'price': 150},
{'product': 'Door', 'price': '100'},
]);
const filtered = collection.where('price', 100);
filtered.all();
//=> [
//=> {'product': 'Chair', 'price': 100},
//=> {'product': 'Door', 'price': '100'}
//=> ]
As you can see, it’s almost a one to one map with the Laravel version and it even includes the fairly new Collection Tap method but it does have some differences when dealing with comparisons:
All comparisons in collect.js are done using strict equality. Using loose equality comparisons are generally frowned upon in JavaScript. Laravel only performs “loose” comparisons by default and offer several “strict” comparison methods. These methods have not been implemented in collect.js because all methods are strict by default.
You can install Collect.js through NPM.
npm install collect.js
For complete documentation and installation take a look at the GitHub repo or the NPM page.
Filed in: Laravel Packages / CollectionsNewsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.
Laravel Jobs

- Full Stack PHP (Mid-Level/Senior) Programmer
-
Remote
PhoneBurner - Software Developer
-
Remote, (US & Canada Only)
Patient Prism - Web Application Developer
-
Chicago Loop
Leading Real Estate Companies of the World - Multiple Laravel Developers (Part-Time)
-
Remote, USA Only
The Great Escape Room - Software Developer
-
Remote (US & Canada)
Alley
Laravel.io Launches Its Next Version
The Laravel community project, Laravel.io, that includes a forum and Pastebin, launched a brand new version. The rele…
The real-time community site Voten goes open-source
The real-time community site Voten that recently made its first public beta has just announced it’s now an open sourc…