arguments object javascript code example
Example 1: js unspecified parameters
function my_log(...args) {
console.log(args);
console.log(...args);
}
Example 2: arguments object in javascript
var sum = 0;
function addAll(){
for (var i = 0; i<arguments.length; i++){
sum+=arguments[i];
}
console.log(sum);
}
addAll(1, 2, 3, 4, 5, 6, 7, 8, 9,10);
Example 3: js array as parameter
function myFunction(a, b, c) {
console.log("a: " + a);
console.log("b: " + b);
console.log("c: " + c);
}
var myArray = [1, -3, "Hello"];
myFunction.apply(this, myArray);
Example 4: arguments object in javascript
function test(a, b, c){
console.log(arguments[0]);
}
test(10, 20, 30);