Reverse a string - Javascript:
//function to reverse a string
function reverseString(str) {
// split the string into an array of characters
var splitString = str.split("");
// reverse the array of characters
var reverseArray = splitString.reverse();
// join the array of characters into a string
var joinArray = reverseArray.join("");
// return the reversed string
return joinArray;
}
//example
const result = reverseString("hello");
//output
console.log(result); //olleh
Top comments (0)