What I want exactly is a function that we can pass two arrays, one the original array of objects with specific order, and the other is an array of objects that has the new target index so the function will return the original array to new order based on the indexes
For example : this is how the original array will look like
const columns=[
{
field: "name",
type: "action",
width: settings.defaultColumnWidth,
},
{
field: "country",
type: "action",
width: settings.defaultColumnWidth,
},
{
field: "phone",
type: "action",
width: settings.defaultColumnWidth,
},
{
field: "email",
type: "action",
width: settings.defaultColumnWidth,
},
]
And the other array that have objects with fields name and the target index to be ordered
const newOrder = [
{
field: "country"
oldIndex: 1
targetIndex: 2
},
]
So the new array that should be returned from the function will be like this
const columns=[
{
field: "name",
type: "action",
width: settings.defaultColumnWidth,
},
{
field: "phone",
type: "action",
width: settings.defaultColumnWidth,
},
{
field: "country",
type: "action",
width: settings.defaultColumnWidth,
},
{
field: "email",
type: "action",
width: settings.defaultColumnWidth,
},
]
I hope my question is clear, thanks in advance for your help