Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

func_get_args for javascript

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]
}
like image 429
Alex Avatar asked Mar 11 '26 03:03

Alex


1 Answers

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);
like image 192
Rocket Hazmat Avatar answered Mar 12 '26 17:03

Rocket Hazmat