Last Updated: Oct. 2023
javascript1function reverseString(str) { 2 return str.split('').reverse().join(''); 3} 4 5reverseString("hello");
You can use this function by passing a string as an argument. For example:
javascript1let reversedString = reverseString("Hello World!"); 2console.log(reversedString); // Outputs: "!dlroW olleH"
In this function, we use the split('')
method to convert the string into an array of characters, reverse()
to reverse the order of the elements in the array, and join('')
to convert the array back into a string.
Keep in mind that this function only works with regular ASCII characters. If you need to handle Unicode characters or emojis, you might need to use more advanced techniques.