# String Reverse how to

String Reverse how to
0

#1

Tell us what’s happening:

``````function reverseString(str) {
return str;
}

reverseString("hello");
var reverse = reverseString.reverse;
``````

Your Browser User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36`.

https://www.freecodecamp.org/challenges/reverse-a-string

#2

Did you have a question?

#3

I did but I figured it out, I tried to reverse the word instead of splitting, reversing, and rejoining.

#4

return str.split("").reverse().join("");

#5

I’m sitting here pushing the single letters into arrays with a for-loop while you solve this in 1 row…

#6

Different approaches.
I prefer the 3rd way

``````function reverseString(str) {
let tempArr = [];
let result = '';

// for(let i = 0; i < str.length; i++) {
//     tempArr.push(str[i]);
// }
// let length = tempArr.length;
// for(let i = 0; i< length; i++){
//     result += tempArr.pop();
// }

// return str.split("").reverse().join("");

for(let i = str.length-1; i >= 0; i--){
result += str[i];
}
return result;
}
``````

#7

On my first Attemp i tried to solve it with a for loop.
but i forgot the `+=` and tried another way to solve it.

i google for array functions and found the .reverse() function and solved it.

but i like the for-loop solving better.

do you know how i can make the word loop infinite, till something is happen?