I'm trying to change function arguments inside another function and then returns it to callee function. I'm trying something like this:
function func(a,b,c) {
console.log(arguments, a, b, c); //[1, true, "a"] 1 true "a"
arguments[0] = 2;
console.log(arguments, a, b, c); //[2, true, "a"] 2 true "a"
arguments = ArgumentsToNumber.apply(this, arguments);
console.log(arguments, a, b, c); //[2, 1, NaN] 2 true "a"
}
function ArgumentsToNumber() {
for (let i = 0; i < arguments.length; i++) {
arguments[i] = Number(arguments[i]);
}
return arguments;
}
func(1, true, 'a');
I want changes in a, b and c variables.
array.mapinfunc?arguments = arguments.map((argument) => Number(argument))arguments[0] = 2. You probably want to convert the arguments to an array first.[].slice.call(arguments)or map over them in some way like[].map.call(arguments, callback)mapfrom array e.g.[].map.call(arguments, Number)