jQuery simulate a continue in a $ .each for

4

If I have the following code

Arreglo.each(function() {
  if(micondicion)
    return false;
}

Exits the cycle, How can I continue with the next one?

    
asked by Fer garcia 29.12.2015 в 17:30
source

2 answers

4

According to the jQuery documentation return any value not false is equivalent to doing continue , so you can return true , 1 , "cadena"

$.each(arr, function() {
    if(continuar) {
        return true; // cualquier valor no falso
    }
});

To make the code more readable you can place a return "continue"; , the idea is that your code clearly indicates the purpose of that line.

    
answered by 29.12.2015 в 17:47
2

Use return true ;

For example:

Arreglo.each(function() { 
  if(micondicion) 
    return true;
}); // Faltó cerrar función
    
answered by 29.12.2015 в 17:31