Defines a static class UFArray, a utility library with static methods for Array instances.

Methods

  • Adds elements from one array to another.

    Type Parameters

    • T

    Parameters

    • target: T[]

      Array to add to

    • source: T[]

      Array to add from

    Returns T[]

    value of aTarget

  • Checks if an array contains a certain value or an object contains a certain key. It is possible to specify multiple values.

    Parameters

    • list: object | any[]

      An array (values are checked) or an object (keys are checked)

    • Rest ...values: any[]

      One or more values to check

    Returns boolean

    True if the array contains one of the values or the object has a key that matches one of the values.

  • Creates an array filled with a certain value.

    Type Parameters

    • T

    Parameters

    • item: T | (() => T)

      Item to fill with or a function that returns a value of the correct type

    • count: number

      Number of items

    • Optional array: T[]

      Array to use, when missing create a new array.

    Returns T[]

    created array or the value of anArray.

  • Creates an array filled with a sequence of integer numbers.

    Parameters

    • count: number

      Number of numbers to fill with

    • start: number = 0

      Starting number (default 0)

    • step: number = 1

      Stepping size (default 1)

    • Optional array: number[]

      Array to use, when missing create a new array.

    Returns number[]

    created array or the value of anArray filled with sequence of integer numbers

  • Finds an item in the array that matched all properties in the aMatch object.

    This method uses the UF.tools.UFObject.equalProperties to compare properties.

    Parameters

    • array: object[]

      Array to look trough

    • match: object

      An object with one or more properties that must be matched.

    • ignoreCase: boolean = false

      When true with string types ignore casing when comparing, false casing should match

    Returns number

    index of entry or -1 if none was found

  • Gets an item in an array for a certain index. If the index is outside the array boundary, return a default value instead.

    Type Parameters

    • T

    Parameters

    • array: T[]

      Array to get item from

    • index: number

      Index of item

    • defaultValue: T

      Default value to return if anIndex is outside the valid boundary.

    Returns T

    item or aDefault if anIndex is invalid.

  • Returns a random item from an array.

    Type Parameters

    • T

    Parameters

    • array: T[]

      Array to get item from

    Returns T

    random item

  • Removes one or more items from a certain index.

    Type Parameters

    • T

    Parameters

    • array: T[]

      Array to remove item(s) from

    • index: number

      Index to start removing at

    • count: number = 1

      Number of items

    Returns T[]

    Value of anArray.

  • Removes duplicate entries.

    Type Parameters

    • T

    Parameters

    • array: T[]

      Array to go through

    Returns T[]

    anArray with duplicates removed.

  • Removes all occurrences of an item from an array.

    Type Parameters

    • T

    Parameters

    • array: T[]

      Array to remove item from

    • item: T

      Item to remove

    • Optional fromIndex: number = 0

      Remove items starting at from this index (0 is first item)

    Returns T[]

    value of anArray

  • Replaces all values that matches aSearchValue with aNewValue.

    Type Parameters

    • T

    Parameters

    • array: T[]

      Array to search trough

    • searchValue: T

      Value to match

    • newValue: T

      Value to replace matching value's with

    • Optional fromIndex: number = 0

      Starting index

    Returns T[]

    anArray value

  • Replaces an item at a certain index with a new value.

    Type Parameters

    • T

    Parameters

    • array: T[]

      Array to replace item in

    • index: number

      Index of item

    • newValue: T

      New value to use

    • copy: boolean = false

      When true make a copy of the array and then replace the value

    Returns T[]

    The value of anArray

  • Replaces multiple search values with a new value. If a value from aSearchValues is found, it is replaced with the value from aNewValues. For each value in aSearchValues, aNewValues must contain a matching new value (in other words aNewValues contains the same number of elements as aSearchValues).

    Type Parameters

    • T

    Parameters

    • array: T[]

      Array to search trough

    • searchValues: T[]

      Array of values to find

    • newValues: T | T[]

      Array of new values to replace found values with.

    Returns T[]

    anArray value

  • Randomly swaps elements in array, shuffling the contents of the array.

    Type Parameters

    • T

    Parameters

    • array: T[]

      Array to shuffle

    • Optional iterations: number

      Number of times to perform swap. If the value is not set, it will be set to 1.5 * length of the array.

    Returns T[]

    value of anArray

  • Assumes an array contains only numeric values, sorts the array based on the value.

    Parameters

    • array: number[]

      Array of numbers

    • Optional reverse: boolean = false

      When true sort in reverse order.

    Returns number[]

    anArray with sorted items

  • Returns the sum of all values in the number array.

    Parameters

    • array: number[]

      Array of numbers

    • start: number = 0

      Starting index, default is 0

    • Optional count: number

      Count, when missing process all entries in the array

    Returns number

    sum of all values in the array

  • Swaps two elements in an array.

    Type Parameters

    • T

    Parameters

    • array: T[]

      Array to update

    • first: number

      Index to first element

    • second: number

      Index to second element

    Returns T[]

    value of anArray

  • Converts all values to int.

    Parameters

    • array: any[]

      Array to update

    Returns number[]

    anArray value

  • Converts all values to Number.

    Parameters

    • array: any[]

      Array to update

    Returns number[]

    anArray value