written by Poul

As a developer in the .NET world where LINQ is first class citizen, when going to JavaScript it seems that some methods are missing. There is even a few libraries that tries to remedy this, but if you are just looking to get the job done the most often used methods are right at hand. (Looking for features such as Lazy-evaluation or observables, linq.js and RxJS offers these).

In the following I’ll list the most used operations and their JavaScript equivalents cheat sheet style. Notice that I’m using Lambda expressions in JavaScript to get the code a bit more concise, if they aren’t available just replace expressions like:

with

All operations are executed against this example:

Notice that some of the operations modifies the source array, if you don’t want that just clone it with:

Every operation is named after the method’s name in LINQ:

All C# JavaScript

Concat C# JavaScript

Count C# JavaScript

Distinct C# JavaScript

Empty C# JavaScript

First C# JavaScript

FirstOrDefault C# JavaScript

ForEach C# JavaScript

GroupBy C# JavaScript

IndexOf C# JavaScript

Last C# JavaScript

LastOrDefault C# JavaScript

OrderBy C# JavaScript

OrderByDescending C# JavaScript

Reverse C# JavaScript

Select C# JavaScript

Single C# JavaScript

Skip C# JavaScript

Take C# JavaScript

Where C# JavaScript

So clearly you don’t need a library if you only need the basic operations. The code above with tests is available at GitHub.

This post is also available in Danish at QED.dk.