Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
Showing default value after returning from each loop

I am trying to do duplication checking on names while adding the records. Initially, I have assigned value to false. In case any mismatch, value is being changed to true inside the each loop and exit the loop. But outside the loop, value again shown as false.

function IsDuplicated(name) {
var value = false;    
masterTable = $('#example').DataTable();
var form_data = masterTable.rows().data();    
$.each(form_data, function (key, value) {
    alert(value.Name);
    if (name== value.Name) {            
        value = true;
        alert(value+ " 1")
        return false;
    }
});
alert(value+ " 2")
return value;
}

Can you help why it is changing to default value after returning from the each loop?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It's cleaner if you do that using find instead

function IsDuplicated(name) {
   
   const masterTable = $('#example').DataTable();
   const data = masterTable.rows().data();    
   
   return !!data.find(d => d.Name == name)    
}
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda