Search This Blog

2023/04/21

Javascript getting function argument as array

 arguments is an array-like object accessible inside functions that

contains the values of the arguments passed to that function.

function func1(a, b, c) {
console.log(arguments[0]);
// Expected output: 1
console.log(arguments[1]);
// Expected output: 2
console.log(arguments[2]);
// Expected output: 3
}
func1(1, 2, 3);

Output:
1
2
3

No comments:

Post a Comment