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
Mostrar matriz de getElementById

Me gustaría usar document.getElemntById como un "nombre" de la matriz de listado

 function aircraft(operator) { var typ = document.getElementById('typ').value; var B738 = ['39.5', '35.8', '12.5', '2', '79000', '2930', 'M0.785', '189']; document.getElementById('dlugosc').textContent = "Długość: " + B738[0] + 'm'; document.getElementById('szerokosc').textContent = "Szerokość: " + B738[1] +'m'; document.getElementById('wysokosc').textContent = "Wysokość: " + B738[2] +'m'; document.getElementById('silniki').textContent = "Ilość silników: " + B738[3]; document.getElementById('mtow').textContent = "MTOW: " + B738[4] + 'kg'; document.getElementById('zasieg').textContent = "Zasięg: " + B738[5] + 'nm'; document.getElementById('predkosc').textContent = "Prędkość max.: " + B738[6]; document.getElementById('pasazerowie').textContent = "Pasażerowie max.: " + B738[7]; }

Y puedo enumerar todo desde la matriz B738, pero me gustaría tener más matrices y usar diferentes nombres de listas de matrices como var typ , pero no funciona

 function aircraft(operator) { var typ = document.getElementById('typ').value; var B738 = ['39.5', '35.8', '12.5', '2', '79000', '2930', 'M0.785', '189']; var A320 = ['39.5', '35.8', '12.5', '2', '79000', '2930', 'M0.785', '189']; document.getElementById('dlugosc').textContent = "Długość: " + typ[0] + 'm'; document.getElementById('szerokosc').textContent = "Szerokość: " + typ[1] +'m'; document.getElementById('wysokosc').textContent = "Wysokość: " + typ[2] +'m'; document.getElementById('silniki').textContent = "Ilość silników: " + typ[3]; document.getElementById('mtow').textContent = "MTOW: " + typ[4] + 'kg'; document.getElementById('zasieg').textContent = "Zasięg: " + typ[5] + 'nm'; document.getElementById('predkosc').textContent = "Prędkość max.: " + typ[6]; document.getElementById('pasazerowie').textContent = "Pasażerowie max.: " + typ[7]; }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No puede usar directamente el valor de typ como una variable en la forma en que lo está intentando, pero puede usarlo como un indexador en un objeto. Haga que sus matrices tengan propiedades en un objeto:

 var myArrays = { B738: ['39.5', '35.8', '12.5', '2', '79000', '2930', 'M0.785', '189'], A320: ['39.5', '35.8', '12.5', '2', '79000', '2930', 'M0.785', '189'] };

Luego puede usar typ para hacer referencia a esas propiedades:

 document.getElementById('dlugosc').textContent = "Długość: " + myArrays[typ][0] + 'm';
about 4 years ago · Santiago Trujillo 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!