array

Advanced utilities for JavaScript array manipulation with support for nested structures, merging, filtering, and more.

Functions

Function
Description
Example

find

Finds an element recursively in nested arrays

dphelper.array.find(array, 'key')

delete

Deletes an element recursively by key

dphelper.array.delete(array, 'key')

merge

Deep merges two objects/arrays (safe from prototype pollution)

dphelper.array.merge(arrA, arrB)

mergeByKey

Merges two arrays of objects via a specific key

dphelper.array.mergeByKey(arrA, arrB, 'id')

unique

Removes duplicate values from an array

dphelper.array.unique(array)

asc

Sorts array in ascending order

dphelper.array.asc(array)

desc

Sorts array in descending order

dphelper.array.desc(array)

duplicates

Finds duplicate elements in an array

dphelper.array.duplicates(array)

even

Filters even numbers from an array

dphelper.array.even(array)

odd

Filters odd numbers from an array

dphelper.array.odd(array)

toObj

Converts an array to an object

dphelper.array.toObj(array)

sumColumn

Sums values of a column in a multidimensional array

dphelper.array.sumColumn(arr, 0)

shuffle

Randomly shuffles elements (Fisher-Yates algorithm)

dphelper.array.shuffle(array)

generate

Generates an array of random numbers (1 to n)

dphelper.array.generate(10)

testArrayInt

Checks for missing numbers in a consecutive sequence

dphelper.array.testArrayInt([1,2,4])

rand32

Generates an array of random 32-bit unsigned integers

dphelper.array.rand32(5)

findindex

Finds the index of an element by key

dphelper.array.findindex(array, 'name')

pathToJson

Converts an array of paths into a JSON object

dphelper.array.pathToJson(paths, '/')

deepClone

Creates a deep clone using structuredClone

dphelper.array.deepClone(array)

match

Finds intersection between two arrays

dphelper.array.match(arrA, arrB)

Description

Comprehensive array manipulation library that provides utilities for:

  • Recursive operations - Find, delete in nested structures

  • Merging - Deep merge with prototype pollution protection

  • Filtering - Even/odd numbers, duplicates

  • Sorting - Ascending/descending order

  • Generation - Random numbers, sequences

  • Conversion - Array to object, paths to JSON

Usage Examples

Finding Elements in Nested Arrays

Deep Merging Objects

Merging Arrays by Key

Finding Duplicates

Filtering Even/Odd Numbers

Sum Column in Multidimensional Array

Shuffle Array (Fisher-Yates)

Generate Random Number Sequence

Test for Consecutive Integers

Generate Random 32-bit Integers

Path to JSON Conversion

Deep Clone Array

Find Array Intersection

Details

  • Author: Dario Passariello

  • Version: 0.0.2

  • Creation Date: 20210101

  • Last Modified: 20260220

  • Environment: Works in both client and server environments


Automatically generated document

Last updated