super-array-tools
v1.0.0
Published
A collection of super useful array utilities for JavaScript
Maintainers
Readme
Super Array Tools
A collection of 10 powerful array utilities for JavaScript/Node.js.
Installation
npm install super-array-toolsUsage
require('super-array-tools');
// Now all arrays have these additional methods
const numbers = [1, 2, 3, 2, 4];
const people = [
{ name: 'Alice', age: 21 },
{ name: 'Bob', age: 21 },
{ name: 'Charlie', age: 30 }
];
// Example uses
console.log(numbers.sum()); // 12
console.log(numbers.unique()); // [1, 2, 3, 4]
console.log(people.groupBy('age'));API Documentation
1. .sum()
Returns the sum of all numbers in the array.
2. .unique()
Returns a new array with duplicates removed.
3. .chunk(size)
Splits array into chunks of the specified size.
4. .shuffle()
Returns a new array with elements randomly shuffled.
5. .groupBy(key)
Groups array of objects by the specified property.
6. .compact()
Removes all falsy values (false, 0, "", null, undefined, NaN).
7. .intersect(arr)
Returns elements that exist in both arrays.
8. .difference(arr)
Returns elements not present in the other array.
9. .countBy(callback)
Counts occurrences grouped by callback return value.
10. .deepFlatten()
Recursively flattens nested arrays.
License
MIT
