reverse string javascriot code example
Example 1: javascript reverse a string
function reverseString(s){
return s.split("").reverse().join("");
}
reverseString("Hello");
Example 2: reverse string javascript
const reverse = (str) => str.split("").reverse().join("");
function reverse1(str) {
const arr = str.split("");
arr.reverse();
const res = arr.join("");
return res;
}
function reverse2(str) {
let res = "";
for (let i = 0; i < str.length; i++) res = str[i] + res;
return res;
}
function reverse3(str) {
return str.split("").reduce((output, char) => {
return char + output;
}, "");
}
Example 3: reverse string javascript
const reverse = (str) => str.split("").reverse().join("");
Example 4: javascript how to reverse a string
function reverseString(str) {
var splitString = str.split("");
var reverseArray = splitString.reverse();
var joinArray = reverseArray.join("");
return joinArray;
}
reverseString("hello");
Example 5: reverse the string in javascript
function reverseString(str) {
return str
.split("")
.reverse()
.join("");
}