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

132
Views
JS: pase elementos de matrices como parámetros para una función

por ejemplo:

 function example({array 1 item x}, {array 2 item x})

Me imagino que necesitaré algún tipo de bucle for que pase cada elemento individualmente con el elemento equivalente de ambas matrices.

código real:

 function hide(bool, item) { if (bool) { document.getElementById(item).classList.add("hide"); document.getElementById(item).classList.remove("show"); bool = false; } }

Necesito ejecutar esto para cada id que quiero ocultar y mostrar, así que pensé que podría poner la lista de bools y la lista de elementos en una matriz y ejecutarlos individualmente para eliminar la redundancia innecesaria.

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

0

Si desea ocultar y mostrar el elemento usando una llamada de función

esto ocultará o mostrará múltiples elementos por id.

 function showAndHide(bool, item) { if (bool.length !== item.length) throw new Error('bool and item length is different') bool.forEach((bool2, index) => { if (bool2) { document.getElementById(item[index]).classList.add("show"); document.getElementById(item[index]).classList.remove("hide"); } else { document.getElementById(item[index]).classList.add("hide"); document.getElementById(item[index]).classList.remove("show"); } }) }
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!