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

139
Views
Using Array.pop and Array.indexOf togther are not working

I'm trying to use Array.pop(Array.indexOf(value)) but it delete the last element in the index even if the value of that index is not same as I set it, can you please help me

  CheckBoxHandler1(e) {
    console.log(e.target.checked, e.target.name);
    let temp = [...this.state.boxes];
    e.target.checked === true
      ? temp.push(e.target.name)
      : temp.pop(temp.indexOf(e.target.name));
    this.setState({
      boxes: temp,
    });
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It happens because Array.prototype.pop() always remove the last element of the array.

If you want to remove one specific element, you need to do the following:

temp.splice(temp.indexOf(e.target.name), 1);
about 4 years ago · Juan Pablo Isaza 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!