Javascript function always returns null

前端 未结 4 555
遥遥无期
遥遥无期 2021-01-20 02:04

I am newbie to the JavaScript world. I have a doubt how the return statement works in JavaScript.

What I am trying to do is to have a function pass one arguments

4条回答
  •  醉酒成梦
    2021-01-20 02:49

    Given Crazy Train's comment, you need to capture the matching value so you can return it later:

    function exampleFunction(param) {
        var match = null;
        $.each(exampleData, function (key, value) {
            if (key == param) {
                match = value;
                return false; // to end the $.each early
            }
        });
        return match;
    }
    

提交回复
热议问题