Say I have this array
arr = ["me", "you", "us", "them"]
I want to be able to move each array element up an index when I click on it, e.g when I click on "them" the array should be like
arr = ["me", "you", "them", "us" ]
I want to use splice() in theory it seems simple but I just can't get my head around it. This is my code
moveRowUp = (to, frm) => {
const {layout} = this.state
if(to >= layout.length){
let diff = to - layout.length;
while((diff--) + 1){
layout.push(undefined)
}
}
layout.splice(to, 0, layout.splice(to, 1)[0]);
// this.setState({
// layout: layout
// })
}