How can I get all the function arguments in javascript inside an array?
function(a, b, c){
// here how can I get an array of all the arguments passed to this function
// like [value of a, value of b, value of c]
}
You want the arguments array object.
function x(a, b, c){
console.log(arguments); // [1,2,3]
}
x(1,2,3);
UPDATE: arguments isn't actually an array, it's an "Array-like object". To make a true array, do this:
var args = Array.prototype.slice.call(arguments);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With