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

1.7K
Views
¿Por qué la declaración 'For' de javascript no funciona en la matriz?

Tengo una secuencia de comandos que crea una serie de palabras a partir de una frase y luego pone en mayúscula cada letra. Obtengo errores de sintaxis cada vez que ejecuto la secuencia de comandos. Aquí está todo el JavaScript relacionado con los cuadros de entrada y salida.

 function validateForm() { var addressInput = regForm.addressBox.value; var postCode = regForm.postCode.value; var townInput = regForm.townBox.value; var addressArray = addressInput.split(" "); var townArray = townInput.split(" "); for (let i = 0; i < addressArray.length; i++) { var addressArray[i] = addressArray[i][0].toUpperCase() + addressArray[i].substring(1); } var addressCap = addressArray.join(" "); for (let i = 0; i < townArray.length; i++) { var townArray[i] = townArray[i][0].toUpperCase() + townArray[i].substring(1); } var townCap = townArray.join(" "); if (addressCap > 1 ) { if (townCap > 1) { if (postCode == 4) { document.getElementById('addressOutput').innerHTML = "Your address is: " + addressCap + ", " + townInput + ", " + postCode; } if (postCode != 4) { document.getElementById('addressOutput').innerHTML = "Please fill out the post code box"; } } if (townCap < 1) { document.getElementById('addressOutput').innerHTML = "Please fill out the town box"; } } if (addressCap < 1) { document.getElementById('addressOutput').innerHTML = "Please check your address for errors"; } }

el error es para i en addressArray[i] y townArray[i] . Siento que es estúpidamente simple, pero estoy perplejo.

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

0

var addressArray[i] = no es una sintaxis válida.

Suelta la var , ya que no estás declarando una variable:

 addressArray[i] = addressArray[i][0].toUpperCase() + addressArray[i].substring(1);
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!