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

98
Views
Remove child with null values in a loop from a HTMLCollection

I have the following where I am setting values inside children where children is of type HTMLCollection.

All these values being set could be null. If null, I wish to remove the child entirely.

But how could I check if a child has value?

Note: Looking to remove it in a loop cos those keys already exists like someToken.

Thus a null check to stop from adding a value to it will not suffice.
I still need to remove the key/value (child) entirely via loop.

Essentially looking for what I would write inside the if check to see if a child in the HTMLCollection has a value.

// this is coming from another file.
const myRef = React.useRef();

myRef.current.children['someToken'] = null;
myRef.current.children['some id'] = 'someId';
myRef.current.children['another data'] = 'anotherData';

[...myRef.current.children].forEach((child) => {

    // I want to remove the child entirely if there is no value. 
    // for example above, the key someToken, the value is set as null
    // so in this case I want to remove the child. 
    // what would I write in the if check here to check that?

    //  if (!child) will always be false since key exists

    if (!child) {
        myRef.current.removeChild(child);
    }

});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I would go for Object.entries:

for (const [key, value] of Object.entries(myRef.current.children)) {
  if (value === null)
    myRef.current.removeChild(child);
}
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!