const data = response.data console.log(data) let tmp = data.groups_with_selected; data.groups_with_selected.splice(7, 2); data.groups_with_selected.splice(2, 0, tmp);
I am trying to splice an element from an array from 7th position, and then insert into 2nd position. But during that process I am successfully able to change the 7th position to 2nd. but issue is after changing the position 7 or 8th position is reflecting in the array.
Juan Pablo Isaza
you can do it like that: you should choose the first element of the array which produced by splice by default to become an item and not an array, then insert it to your array at a certain position;
const temp = data.groups_with_selected.splice(7,1) data.groups_with_selected.splice(2,0,temp )
so it will insert the 8th element in the third position;