I am doing dragndropping and I need to swap the elements when swaping, there is an array of objects and the index of the active object and the one that is swapped, how can I swap them in js without mutating the original object
let allData = [{name:1},{name:2},{name:3}]
I need get after swapping
[{name:2},{name:1},{name:3}]
example what i need to do
case CHANGE_TAB_ORDER:
const {activeElementIndex} = action.payload;
const {swapedElementIndex} = action.payload
return {
...state,
stages: ? here i need to swap objects in array with activeElementIndex and swapedElementIndex
}
stages is array of objects