如何获取函数参数值

How to get the function arguments value?

本文关键字:函数 参数 获取 何获取      更新时间:2023-11-30

我想通过使用arguments[I]循环所有函数arguments值来简化我的电子邮件验证,但它返回"undefined"。

function checkInputRequired(companyNameValue, contactNameValue, publisherEmailValue, publisherEmailConfirmValue)
    {
        // The arguments object is an Array-like object corresponding to the arguments passed to a function.
        for (var i = 0; i < arguments.length; i++)
        {
            // print out 4 undefined
            console.log(arguments[i]);
        }
    }

检查

function checkInputRequired(companyNameValue, contactNameValue, publisherEmailValue, publisherEmailConfirmValue)
    {
        // The arguments object is an Array-like object corresponding to the arguments passed to a function.
        for (var i = 0; i < arguments.length; i++)
        {
            // print out 4 undefined
            console.log(arguments[i]);
        }
    }
checkInputRequired('ddd','bbbbb','sssss','dddddddddd');

当您调用该函数时,它将显示值,否则它将显示未定义的默认值。