I have a $.each method that searches through a JSON to find the variable and I am using this code:
$.each(heroes_json.heroes, function(key, val){
if(val.id == hero){
hero = val.localized_name;
console.log("Hero name is "+hero);
return;
}
else{
console.log("Wrong hero, skipping...");
}
});
The problem however is that I get this in my console log:
So from what I understand, the $.each method is, as described, going over every object in the JSON. How can it be made so that when the desired variable (in this case hero
) is found, that it stops the each method? I am assuming that this is desired for performance purposes?