Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!