JavaScript Equivalents of C# LINQ Methods Blog post

If you are a C# developer then you'll be familiar with LINQ (Language-Integrated Query). You'll also know that the most common flavour of LINQ - LINQ to Objects - contains a number of useful extension methods that work against the IEnumerable<T> interface

These methods are extremely useful for performing operations against collections (arrays, lists etc) such as filtering, selecting and aggregating. Whilst the naming of LINQ methods tends to be derived from SQL (eg. "WHERE", "SELECT", "SUM" etc) the actual operations are more functional in nature. This means that other functional languages -such as, say, JavaScript - have similar operations. However, as primarily a C# developer I tend to "think in LINQ" and I'm often stuck remembering what the JavaScript equivalents of common LINQ methods are.

So, as primarily a memory aid for myself, I created a quick Gist on GitHub that outlines how you perform common LINQ collection queries against JavaScript arrays. The results can seen below:

Download: Download GIST

2 Comments


Joe Avatar

Joe

Great post, this was very helpful! Thanks


Siderite Avatar

Note that LINQ methods are deferred in C#, while using map/filter/reduce creates an array at every step. I've written a LINQ-like library for Javascript using ES6 language features here: https://siderite.dev/blog/linq-in-javascript-linqer/

Just fill in the form and click Submit. But note all comments are moderated, so spare the viagra spam!

Tip: You can use Markdown syntax within comments.