LINQ for JavaScript

4.0.3 · active · verified Sun Apr 19

Linq.js is a comprehensive JavaScript implementation of the .NET Language Integrated Query (LINQ) library, offering a fluent API for querying and manipulating data collections. It includes all the original .NET LINQ methods along with several additions, enabling powerful data transformations and filtering across various iterable objects like arrays, Maps, and Sets. The current stable version is 4.0.3, with a release cadence that has provided incremental updates for improved iteration protocol support and enhanced TypeScript definitions. A key differentiator is its transition to a pure ES module structure in version 4.0.0, making it fully compatible with modern JavaScript environments such as Node.js (v14.13.1 and later), TypeScript projects, Deno, and contemporary web browsers. For projects requiring CommonJS modules or targeting older environments, version 3 of the library remains available.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic LINQ operations including filtering, mapping, and querying iterable objects like Maps, highlighting its fluent API.

// For Node.js (v14.13.1+) with "type": "module" in package.json
import Enumerable from 'linq';

// Example 1: Basic filtering and transformation
let result1 = Enumerable.range(1, 10)
    .where(i => i % 3 === 0)
    .select(i => i * 10)
    .toArray();
console.log('Filtered and multiplied:', result1); // [ 30, 60, 90 ]

// Example 2: Working with objects and iterating over Map/Set
const data = new Map([
    ['apple', 10],
    ['banana', 20],
    ['cherry', 30]
]);
let result2 = Enumerable.from(data)
    .where(([key, value]) => value > 15)
    .select(([key, value]) => ({ fruit: key, quantity: value * 2 }))
    .toArray();
console.log('Querying Map:', result2); // [ { fruit: 'banana', quantity: 40 }, { fruit: 'cherry', quantity: 60 } ]

// Example 3: Finding the first element meeting a condition
let firstBigRadius = Enumerable.toInfinity(1)
    .where(r => r * r * Math.PI > 10000)
    .first();
console.log('First radius for area > 10000:', firstBigRadius);

view raw JSON →