How Do You Reverse a String?
Steps:
- Create a empty string
newString - Create a for loop, the starting point of the loop with be
str.length - 1which will be the last character of the string - Continue for loop till
iis greater than or equals0, decrementiafter each iteration
function reverseString(str) {
let newString = "";
for(let i = str.length - 1 ; i >= 0; i--) {
newString = newString + str[i];
}
return newString;
}
reverseString('hello');