Javascript function always returns null -


i newbie javascript world. have doubt how return statement works in javascript.

what trying have function pass 1 arguments param , looking whether param match key of exampledata object. if match found want return value , break looping of each function break function don't want execute other statement under each function. if no match found function must return null. function return null value.

function examplefunction(param){     $.each(exampledata, function (key, value) {         if(key == param){         return value;         }     });     return null; } 

any insight highly appreciated. thank you.

your example doesn't seem need loop. , returning loop-delegate doesn't you.

you can test if key appears in object using in operator.

function examplefunction(param){   return param in exampledata ? exampledata[param] : null; } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -