To convert the arguments object to an array in JavaScript, we should replace it with the rest operator.
For instance, we write
const sortArgs = (...args) => {
return args.sort((a, b) => {
return a - b;
});
};
to define the sortArgs function.
We use the spread operator to convert the arguments into an array with the ... rest operator.
args then has all the arguments we called sortArgs with.
And then we call args.sort to sort the arguments and returned a new array with the sorted values.