Compute union, intersection, difference and symmetric difference of two lists
Array operations are the fundamental building blocks of data manipulation in programming. Sorting, filtering, mapping, reducing, merging, deduplicating, flattening — these operations transform arrays of data from one form to another. JavaScript's built-in array methods (`Array.prototype.map`, `filter`, `reduce`, `sort`, `flat`, `flatMap`, `every`, `some`, `find`, `findIndex`) provide a functional toolkit that covers the majority of real-world data transformation needs without external libraries.
This tool lets you apply array operations interactively: sort by value, filter by condition, deduplicate, chunk into groups, zip multiple arrays, find intersections and differences, flatten nested arrays, and compute aggregate values (sum, average, min, max). Understanding these operations is fundamental to working with API responses, database query results, form data, and any collection-based data in web and backend development.
`map` transforms each element, producing a new array of the same length: `[1,2,3].map(x => x*2)` → `[2,4,6]`. `filter` keeps only elements matching a predicate, producing a shorter or equal-length array: `[1,2,3].filter(x => x>1)` → `[2,3]`. `reduce` collapses the array to a single value: `[1,2,3].reduce((acc,x) => acc+x, 0)` → `6`. All three return new arrays/values without mutating the original.
By default, `Array.sort()` converts elements to strings and sorts lexicographically — meaning `[10,9,2,1].sort()` → `[1,10,2,9]`. For numeric sort, pass a comparator: `arr.sort((a,b) => a-b)` (ascending) or `arr.sort((a,b) => b-a)` (descending). For object arrays: `arr.sort((a,b) => a.name.localeCompare(b.name))` for locale-aware string comparison. JavaScript sort is NOT guaranteed stable across all engines (though modern engines use stable sort).
For primitives: `[...new Set(array)]` — O(n) time, O(n) space, preserves insertion order. For objects by key: `const seen = new Map(); array.filter(item => { if (seen.has(item.id)) return false; seen.set(item.id, true); return true; })`. Avoid `indexOf` or `includes` in a filter for large arrays — both are O(n) per element, making the overall operation O(n²).
`flat(depth)` flattens nested arrays up to `depth` levels: `[[1,2],[3,[4]]].flat(1)` → `[1,2,3,[4]]`; `flat(Infinity)` flattens all levels. `flatMap(fn)` combines `map` followed by `flat(1)` in a single pass: `arr.flatMap(x => [x, x*2])` is equivalent to `arr.map(x => [x, x*2]).flat()` but more efficient. Use `flatMap` when mapping produces arrays you want to immediately flatten one level.
CSV Viewer · Data Faker · List Sorter · Number List Statistics · Duplicate Line Finder · Tally Counter