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

138
Views
Deleting an element does not work with two children

I want to delete parent element includes all children. When i have one child in parent element it works, but if there are 2 children, it doesn't work.

// **arr is data list**

const handleDelete = (arr, id) => {

    let newArr = [...arr];
    newArr = newArr.filter(item => item.id !== id);
    const children = newArr.filter(item => item.parentId === id);
    if (children.length > 0) {
      newArr = newArr.filter(item => item.parentId !== id);
      children.forEach(item => handleDelete(newArr, item.id));
      return;
    }
    dispatch(deleteList(newArr));
    return newArr;
  };
about 4 years ago · Juan Pablo Isaza
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!