π¨ JavaScript Array β Complete Topic Index
Parent: DSA Master Index
π¦ Subtopics
| # | Subtopic | File | Key Concepts |
| 1 | Array Basics | 01-basics/ | Creation, destructuring, spread, CRUD, common mistakes |
| 2 | JS Array Methods | 02-js-array-methods/ | map, filter, reduce, find, flat, every, some + when to use |
| 3 | Sorting | 03-sorting/ | Array.sort() gotchas, comparators, all algorithms |
| 4 | Searching | 04-searching/ | indexOf, find, binary search, 2D matrix |
| 5 | Two Pointers | 05-two-pointers/ | Pair sum, palindrome, trap water |
| 6 | Sliding Window | 06-sliding-window/ | Fixed/variable window, Map-based frequency |
| 7 | Prefix Sum | 07-prefix-sum/ | Range queries, Kadane's, subarray sum = k |
| 8 | Interview Questions | 08-interview-questions/ | Top 20 JS questions with solutions |
π§ JavaScript Array β Big Picture
Array (JS)
βββ Creation β literal, Array(), from(), of()
βββ Built-in Methods β 30+ methods (mutating vs non-mutating)
βββ Sorting β .sort() quirks, custom comparators
βββ Searching β find/indexOf + binary search
βββ Two Pointers β O(n) for O(nΒ²) problems
βββ Sliding Window β Subarray / substring problems
βββ Prefix Sum β Precompute for O(1) range queries
β±οΈ Time Complexity Cheat Sheet
| Operation | JS Array | Notes |
| Access by index | O(1) | Direct |
| push / pop | O(1) | End of array |
| shift / unshift | O(n) | Start shifts all elements |
| splice (middle) | O(n) | Shifts elements |
| indexOf / includes | O(n) | Linear scan |
| sort() | O(n log n) | TimSort in V8 |
| map / filter / reduce | O(n) | Each iterates once |
| flat(depth) | O(n*d) | d = depth level |
π― Interview Pattern Recognition
| Keyword in Question | Technique to Use |
| "subarray of size k" | Sliding Window (Fixed) |
| "longest subarray with..." | Sliding Window (Variable) |
| "pair that sums to X" | Two Pointers |
| "duplicates" | Set or Map |
| "sorted array, find..." | Binary Search |
| "range sum", "prefix" | Prefix Sum |
| "sort this array" | Array.sort() with comparator |
| "frequency of elements" | Map counter |
| "rotate array" | Two Pointers (reverse trick) |
| "unique elements" | Set |
β‘ JS-Specific Quick Reference
| Task | Method |
| Remove duplicates | [...new Set(arr)] |
| Flatten array | arr.flat(Infinity) |
| Sum all elements | arr.reduce((a,b) => a+b, 0) |
| Max value | Math.max(...arr) |
| Check all pass | arr.every(x => x > 0) |
| Check any pass | arr.some(x => x > 0) |
| Find first match | arr.find(x => x > 5) |
| Group by property | arr.reduce((acc, x) => ...) |
| Clone array | [...arr] or arr.slice() |
| Fill with value | new Array(n).fill(0) |