.swap(idx1,idx2)

Description

Swap is a method that swaps two values in an array

Parameters

Swap takes the index of the first value and the index of the second value as parameters.

Usage On Arrays

arr = ["wow","hello","world"]
// setup the array

log arr.swap(2,3)
// returns ["wow","world","hello"]
// the values at index 2 and 3 were swapped

Last updated

Was this helpful?