LinqJS a javascript linq library

While working with javascript I suddenly realized I missed something very important. As as C# developer I think that LINQ rocks and I use it to make all those boring foreach loops better to read and easier to understand. So the first thing I did after writing a for loop in javascript was looking for a linq library.


Linqjs can be found here and according to their site they support the following things:

  • implement all .NET 4.0 methods and many extra methods (inspiration from Rx, Achiral, Haskell, Ruby, etc…)
  • complete lazy evaluation
  • full IntelliSense support for VisualStudio
  • two versions – linq.js and jquery.linq.js (jQuery plugin)
  • support Windows Script Host
  • binding for Reactive Extensions for JavaScript(RxJS) and IntelliSense Generator -> see documentation
  • NuGet install support(linq.js, linq.js-jQuery, linq.js-Bindings)

All full reference of the functions and examples can be found here:

After installing I was all ready to use it. But there are some small differences between the C# and the JS version:


var selectedUsers = allUsers.Where(u=>u.IsSelected).ToList();


var selectedUsers = Enumerable.From(allUsers).Where(function(u) {return u.isSelected}).ToArray();

var selectedUsers = Enumerable.From(allUsers).Where("u => u.isSelected").ToArray();

Important to notice here is that Enumerable.From makes an enumerable sequence from elements. Also when you use the js lamba’s in code they are hard to debug. When you create an anonymous function you can put a breakpoint in it.

LinqJs is a powerful library which makes working with data in javascript easier for every developer. However if you haven’t worked with LINQ in C# before the constructs may seem strange at first. But it would suggest you give it a try, it works wonderfully in C# and really makes your live easier. If you’re a C# developer then there’s no need to convince you that linq rocks! Just use it!

Leave a comment

Your email address will not be published.