• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

78
Views
Eliminar niño con valores nulos en un bucle de una HTMLCollection

Tengo lo siguiente donde estoy configurando valores dentro de los niños donde los niños son del tipo HTMLCollection .

Todos estos valores que se establecen podrían ser nulos. Si es nulo, deseo eliminar el elemento secundario por completo.

Pero, ¿cómo podría verificar si un niño tiene valor?

Nota: buscando eliminarlo en un bucle porque esas claves ya existen como someToken .

Por lo tanto, una verificación nula para evitar agregarle un valor no será suficiente.
Todavía necesito eliminar la clave/valor (hijo) por completo a través de bucle.

Esencialmente buscando lo que escribiría dentro del control if para ver si un elemento secundario en HTMLCollection tiene un valor.

 // 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); } });
almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Yo iría por Object.entries :

 for (const [key, value] of Object.entries(myRef.current.children)) { if (value === null) myRef.current.removeChild(child); }
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error