Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
javascript undefine keyword prefix with a string

i try to reverse a string by finding the lenght first, using for-loop and den loops throught the range from the lenght to zero and concat it with other variable in order to store it in a reverse order, but i always get undefined prefix to it.

code -

function reverse1(str) {
  let len = 0;
  for (let i in str) {
    len += 1;
  }
  var r = "";
  for (var i = len; i >= 0; i--) {
    r += str[i];
  }
  return r;
}
console.log(reverse1("hello"));

output- undefinedolleh

How to get rid of this undefined keyword which get prefix in the reverse string

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You Are assigning i in for loop with string length , it should be start from len-1

for (var i = len-1; i >= 0; i--)
about 4 years ago · Juan Pablo Isaza Denunciar

0

  • Maybe there is an easier way to do this, if that what are you going for.
const str = 'Hello World';
const reversed = str .split('').reverse().join('')
console.log(reversed); // dlroW olleH
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda