[Javascript] How to reverse a string without using inbuilt functions?


I want to reverse a string without using in-built functions like reverse(), How can I do that in Javascript?

1 Answer

3 years ago by

You can use a loop and traverse the string from backwards. In the below example, I'm using while loop, but you can also use for loop for the same.

let str = "hello world";

let reverseString = "";
let i = str.length-1;

while(i >= 0) {
  reverseString += str[i];
  i--;
}

console.log(reverseString)

Run here https://onecompiler.com/javascript/3xnrvmaz2

3 years ago by Meera