Answers for "javascript array move element one position"

1

javascript array move element one position

// Move element '3' to where currently '1' is
const numbers = [ 1, 2, 3, 4, 5 ]
const numbersOriginal = Object.assign(numbers)
const sourceIndex = 2
const targetIndex = 0
numbers.splice(targetIndex, 0, numbers.splice(sourceIndex, 1)[0])
console.log(numbersOriginal)
console.log(numbers)
Posted by: Guest on April-16-2021

Code answers related to "javascript array move element one position"

Code answers related to "Javascript"

Browse Popular Code Answers by Language