How to use the Arguments Object in a Function in JavaScript ?
Last Updated :
02 Feb, 2024
The arguments
object is a special object available in JavaScript functions that holds all the parameters passed to the function. It allows you to access the arguments passed to a function even if the function was not explicitly defined with named parameters.
Example: Here, the exampleFunction
takes no named parameters, but you can still access the arguments using the arguments
object. The arguments
object is similar to an array in that it has a length property and you can access its elements using numeric indices.
Javascript
function exampleFunction() {
for (let i = 0; i < arguments.length; i++) {
console.log(arguments[i]);
}
}
exampleFunction(1, 'hello' , true , [1, 2, 3]);
|
Output
1
hello
true
[ 1, 2, 3 ]
Share your thoughts in the comments
Please Login to comment...