Options
All
  • Public
  • Public/Protected
  • All
Menu

Utilities to perform common array operations

Hierarchy

  • ArrayUtils

Index

Methods

Static forceNonEmptyArray

  • forceNonEmptyArray(value: any, valueName?: string, errorMessage?: string): void
  • Strictly check that the provided value is a non empty array or throw an exception

    throws

    Error If the check fails

    Parameters

    • value: any

      A value to check

    • Default value valueName: string = ""

      The name of the value to be shown at the beginning of the exception message

    • Default value errorMessage: string = "must be a non empty array"

      The rest of the exception message

    Returns void

    void

Static getDuplicateElements

  • getDuplicateElements(array: any[]): any[]
  • Get all the duplicate values on the provided array Duplicate values with different data types won't be considered as equal ('1', 1 will return false)

    Parameters

    • array: any[]

      An array containing some elements to test

    Returns any[]

    list with all the elements that are duplicated on the provided array

Static hasDuplicateElements

  • hasDuplicateElements(array: any[]): boolean
  • Check if the given array contains duplicate values or not. Duplicate values with different data types won't be considered as equal ('1', 1 will return false)

    Parameters

    • array: any[]

      An array containing some elements to test

    Returns boolean

    True if there are duplicate values, false otherwise

Static isArray

  • isArray(value: any): boolean
  • Tells if the given value is an array or not

    Parameters

    • value: any

      A value to check

    Returns boolean

    true if the given value is an array, false otherwise

Static isEqualTo

  • isEqualTo(array1: any[], array2: any[]): boolean
  • Check if two provided arrays are identical (have exactly the same elements and in the same order).

    Parameters

    • array1: any[]

      First array to compare

    • array2: any[]

      Second array to compare

    Returns boolean

    true if arrays are exactly the same, false if not

Static isStringFound

  • isStringFound(array: any[], str: string, caseSensitive?: boolean): boolean
  • Check if the provided string is found inside the provided array structure. This method will recursively search inside all the provided array elements and test if the provided string is found. Search will be performed inside any array structures like arrays or other objects. Result will be positive even if any string on the array contains the searched text as a substring.

    Parameters

    • array: any[]

      The array where the string will be looked for

    • str: string

      The string that will be searched on the array

    • Default value caseSensitive: boolean = true

      True (default) to perform a case sensitive search, false otherwise

    Returns boolean

    True if the string is found anywhere inside the provided array, false otherwise

Static removeDuplicateElements

  • removeDuplicateElements(array: any[]): any[]
  • remove all the duplicate values on the provided array Duplicate values with different data types won't be considered as equal ('1', 1 will not be removed)

    Parameters

    • array: any[]

      An array with possible duplicate values

    Returns any[]

    The same provided array but without duplicate elements

Static removeElement

  • removeElement(array: any[], element: any): any[]
  • Remove the specified item from an array

    Parameters

    • array: any[]

      An array (it will not be modified by this method)

    • element: any

      The element that must be removed from the given array

    Returns any[]

    The provided array but without the specified element (if found). Note that originally received array is not modified by this method

Generated using TypeDoc