I wanted to have an optional boolean
parameter to a function call:
function test() {
if (typeof(arguments[0]) === 'boolean') {
// do some stuff
}
// rest of function
}
I want the rest of the function to only see the arguments
array without the optional boolean
parameter. First thing I realized is the arguments
array isn't an array! It seems to be a standard Object
with properties of 0, 1, 2, etc. So I couldn't do:
function test() {
if (typeof(arguments[0]) === 'boolean') {
var optionalParameter = arguments.shift();
I get an error that shift()
doesn't exist. So is there an easy way to remove an argument from the beginning of an arguments
object?