How is possible to change 3/4 elements? Expected output is [1,2,4,3,5]
let list = [1,2,3,4,5]; const removeElement = list.indexOf(3); // remove number 3 list
Arrays are objects, use Object.assign() and access elements with property name expressions.
var numToMove = 2; console.log(Object.assign(list, {[numToMove]: list[numToMove+1]}, {[numToMove+1]: list[numToMove]})); // [1, 2, 4, 3, 5]