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

123
Views
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 answers
Answer question

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 Report

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 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!