Javascript function always returns null

javascript

Solution

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;
}

Problem

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 `param` and looking whether the `param` match the key of the `exampleData` object. If match found I want to return the value and break the looping of each function also break the function I don't want to execute any other statement under the each function. If no match found the function must return null. But currently the function always return null value. ``` function exampleFunction(param){ $.each(exampleData, function (key, value) { if(key == param){ return value; } }); return null; } ``` Any insight into this would highly be appreciated. Thank you.

Original source

Related problems