I have an array of objects, I want to move any object In the same array. I really tried hard but did not a solution. could someone please help me with how to resolve this issue?
[{name:'user 1'}, {name:'user 2'},{name:'user 3'},{name:'user 4'},{name:'user 5'}]
I want to select {name:'user 2'}
and move to after {name:user 3}
The expected result will be
[{name:'user 1'},{name:'user 3'},{name:'user 2'},{name:'user 4'},{name:'user 5'}]
[a[1], a[2]] = [a[2], a[1]];
and finding them can be done witharray.findIndex(e => e === target)
orindexOf
.