Anjan Dutta
How to reverse a string in JavaScript
How to reverse a string in JavaScript
Created On: 02/10/2021
To reverse a string in javascript, we have to split the string into an array first. Then using the reverse()
function, we can reverse the array. Finally, we have to use the join()
method to join the array elements back as a string. See the below code.
let text = "Hello World"let reversedString = text.split('').reverse().join('');console.log(reversedString);
// Output// > dlroW olleH