如何获取函数参数值?

时间:2016-04-03 02:09:50

标签: javascript

我希望通过使用arguments [i]循环遍历所有函数参数值来简化我的电子邮件验证,但它返回“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]);
        }
    }

1 个答案:

答案 0 :(得分:1)

检查出来

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');

当您调用该函数时,它将显示值,否则显示默认值undefined。