Desidero utilizzare return false
per interrompere un .each() ma anche restituire un valore allo stesso tempo. Come posso fare questo?Come uscire da .each() e restituire un valore per una funzione
Si prega di fare riferimento ad un work-around funzionare per vedere quello che sto cercando di fare:
function HasStores(state) {
var statehasstores = false;
$(stores).each(function (index, store) {
if (state == store.state && store.category == "meyers") {
statehasstores = true;
return false; // break
}
});
return statehasstores;
}
Cosa Id piace fare in pseudo codice è:
Function() {
for() {
if found {
return true;
}
}
return false;
}
Lo sta già facendo! Guarda il mio esempio http://jsfiddle.net/aXkcW/ – BrunoLM
Questo è il primo in SO che ho trovato la risposta che stavo cercando all'interno della domanda OPI chiesto lol – NecipAllef