Javascript function always returns null

前端 未结 4 457
遥遥无期
遥遥无期 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:52

    Your example doesn't seem to need a loop. That and returning from the loop-delegate doesn't do anything for you.

    You can test if a key appears in an object using the in operator.

    function exampleFunction(param){
      return param in exampleData ? exampleData[param] : null;
    }
    

提交回复
热议问题