Function trimEnd

  • Category

    Removes the trailing end characters from a string.

    Time complexity: O(n)

    Space complexity: O(n)

    Parameters

    • string: string

      The string to trim

    • end: string

      The character to remove from the end of string

    Returns string

    A string with the leading end characters removed

    Example

    trimEnd('aabbcc', 'c'); // 'aabb'
    

    See

    (trimStart:1) to do the same thing but trim from the start of a string

    String

  • Category

    Removes the trailing end characters from an array.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T

    Parameters

    • array: readonly T[]

      The array to trim

    • end: T

      The character to remove from the end of array

    Returns T[]

    A shallow-copied array with the trailing start characters removed

    Example

    trimEnd(['a', 'a', 'b', 'b', 'c', 'c'], 'c'); // ['a', 'a', 'b', 'b']
    

    See

    (trimStart:2) to do the same thing but trim from the start of an array

    Array