pols-utils - v5.3.11
    Preparing search index...

    Function swap

    • Exchanges the position of two elements in an array.

      Parameters

      • array: unknown[]

        The target array.

      • originIndex: number

        The index of the first element to swap.

      • destinationIndex: number

        The index of the second elemento to swap.

      Returns unknown[]

      The same target array.

      const myarray = [0, 1, 2, 3, 4]
      PUtilsArray.swap(myarray, 1, 4)
      console.log(myarray) // 0, 4, 2, 3, 1