Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in

Posted on

Reverse a string in Javascript

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;

const result = reverseString("hello");

console.log(result); //olleh

Enter fullscreen mode Exit fullscreen mode

Top comments (0)