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

146
Views
¿Cómo puedo mostrar "-" tan largo como la longitud de la cadena en el cuadro de texto?

tengo esta lista:

 let teams = [ "real madrid", "barcelona", "milan", "inter", "juventus", "manchester united", "manchester city", "liverpool", "arsenal", "chelsea", "bayern munich", ];

Escribí un código para elegir un elemento aleatorio de esta lista, pero quiero mostrar "-" siempre que la longitud del elemento.

Por ejemplo: elige real madrid ... Quiero esto - - - - - - - - - - en el cuadro de texto.

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

0

Use String.prototype.replace() con un RegExp pequeño que coincidirá con cualquier carácter \S que no sea un espacio, y reemplácelo con un guión - (PD: g significa reemplazo global )

 const str = "Real Madrid"; const hyphenated = str.replace(/\S/g, "-"); console.log(hyphenated);

¡Feliz ahorcado !

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!