#arrays Clear
Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
TypeScript takeWhile / dropWhile
Consume or skip leading elements as long as a predicate holds. Useful for parsing prefixed sequences (e.g. all leading whitespace tokens, all unread notifications, etc.).
Bash Deduplicate Array (preserve order)
Bash's associative arrays let you dedupe in a single pass while keeping the original order — `sort -u` would shuffle.
Bash Associative Array (hash map)
Bash 4+ supports key-value associative arrays. Must `declare -A` first — Bash won't infer it. Iterate keys with !arr[@].
PHP Index Array By Column
Rekey a list of rows by one of their column values, so $byId[42] gives the row with id=42. Equivalent to array_column($rows, null, $key).
Bash Slice Bash Array
Bash supports Python-like array slicing via ${arr[@]:offset:length}. Lets you take/skip elements without external tools.
PHP Set Nested Value by Dot Path
Mutate a nested array by dot path, auto-creating any intermediate arrays. Companion to getPath; together they replace a lot of isset+array_key_exists ladders.
TypeScript range — Lazy Number Iterator
A generator-based numeric range: `[start, end)` with an optional step. Lazy so it doesn't allocate a huge array up front; consume with for…of or Array.from.
Bash Check If Array Contains Element
A pure-bash membership test using `=~` or by iterating. Both are useful — pick by readability vs. speed.
Bash Array Basics (index + iterate)
Bash 4+ arrays — declare, access by index, get all elements with [@], length with #. The quoting matters: "${arr[@]}" preserves each element; ${arr[@]} word-splits.
Bash Split String into Array on Delimiter
Use IFS + read or readarray to split safely. Don't use word-splitting tricks — they break on edge cases (empty fields, spaces in values).
PHP Partition Array Into Two Buckets
Split an array into [matches, non-matches] using a predicate callback. Single pass, preserves order, returns two lists.
PHP Unique by Callback
Like array_unique, but the uniqueness test is a callback that returns the key to dedupe by. Useful for "unique by ID" or "unique by lowercased email" across arrays of objects/rows.
TypeScript Sum / Mean / Median (numeric arrays)
The descriptive-stat trio for number[]. Median sorts a copy so the input is left alone. Empty input returns 0 / 0 / 0 rather than NaN — opinionated, but predictable.
TypeScript Shuffle (Fisher-Yates)
Uniformly shuffle an array in place using the modern Fisher-Yates algorithm. Returns the same array for chaining. Use crypto.getRandomValues for cryptographic uses.
PHP Get Nested Value by Dot Path
Read deeply-nested array values like Lodash _.get(). Use a "a.b.c" string instead of nested isset checks; returns a default on any missing segment.
TypeScript partition — Split by Predicate
Split an array into [pass, fail] in a single pass. Type guard overload lets the truthy bucket get a narrowed type when you pass a `x is T` predicate.
TypeScript groupBy (with key callback)
Group a list into a record keyed by whatever the callback returns. Like Lodash _.groupBy or the new Object.groupBy in modern runtimes. Generic enough to handle string, number, or symbol keys.
PHP Pluck Column From Array of Rows
Extract a single column from a list of associative arrays into a flat list. Common transformation for SELECT results — equivalent to array_column with optional indexing key.