Calculates the sum of the array values. Supports bare number arrays or objects with a selector to extract numeric values.
The sum of all values (0 for empty arrays)
Returns a new array with only unique elements based on strict equality (===). Preserves order of first occurrence.
A new array with duplicate values removed
Splits the array into chunks (sub-arrays) of a specified maximum size.
Maximum size of each chunk (must be positive integer)
A new array of chunks, where each chunk has at most size elements
Calculates the average (mean) of the array values. Supports bare number arrays or objects with a selector to extract numeric values.
The average of all values (0 for empty arrays)
Removes all falsy values from the array.
Removes: false, null, 0, "" (empty string), undefined, NaN.
A new array with all falsy values removed
Enumerates the array into tuples of [value, index]. Similar to Python's enumerate but returns value first.
An array of [value, index] tuples
Returns a new sorted copy of the array in ascending order. Creates a new array without modifying the original.
A new array sorted in ascending order
Returns a new sorted copy of the array in descending order. Creates a new array without modifying the original.
A new array sorted in descending order
Swaps the elements at two indices within the array. Modifies the array in place and returns the array itself (for chaining).
First index to swap
Second index to swap
The modified array (same reference as this)
Returns a new array with elements shuffled randomly. Uses Fisher-Yates algorithm for uniform distribution. Does not modify the original array.
A new shuffled array
Converts an array to a Map using keys and optionally values extracted from elements. Supports multiple input formats: pairs array, property key, or selector functions.
The type of Map keys
The type of Map values
A Map with extracted key-value pairs
// From pairs
[['a', 1], ['b', 2]].toMap(); // Map { 'a' => 1, 'b' => 2 }
// Using property key
[{id: 1, name: 'foo'}, {id: 2, name: 'bar'}].toMap('id');
// Map { 1 => {id: 1, name: 'foo'}, 2 => {id: 2, name: 'bar'} }
// Using selectors
[{id: 1, name: 'foo'}].toMap(x => x.id, x => x.name);
// Map { 1 => 'foo' }
// Default (uses index)
['a', 'b'].toMap();
// Map { 0 => 'a', 1 => 'b' }
Converts an array to a plain JavaScript object using keys and optionally values extracted from elements. Leverages Map.prototype.toObject() internally for consistency and validation.
Type of object keys (must be PropertyKey: string | number)
Type of object values
A plain object with array elements as properties
// From pairs
[['a', 1], ['b', 2]].toObject(); // { a: 1, b: 2 }
// Using property key
[{id: 1, name: 'foo'}, {id: 2, name: 'bar'}].toObject('id');
// { 1: {id: 1, name: 'foo'}, 2: {id: 2, name: 'bar'} }
// Using selectors
[{id: 1, name: 'foo'}].toObject(x => x.id, x => x.name);
// { 1: 'foo' }
// Default (uses index)
['a', 'b'].toObject();
// { 0: 'a', 1: 'b' }
Returns the first element of the array, or
undefinedif the array is empty.