javascript

How to Reverse A String in Javascript


In this article, you will learn how to reverse a string in Javascript.

Let’s say you have a string variable named ‘a’ with value “codesource”.

var a = "codesource";

In order to reverse the string variable, you can use the split(), reverse() and join() methods.

var a = "codesource";

console.log(a.split("").reverse().join(""));

Note: The split() method functions by splitting a string into an array of substrings. The reverse() method functions by reversing the order of elements in an array. The join method functions by concatenating the elements of an array into a string.


Share on social media

//