This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
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.
The post How to Reverse A String in Javascript appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
Ariessa Norramli | Sciencx (2021-02-17T07:44:25+00:00) How to Reverse A String in Javascript. Retrieved from https://www.scien.cx/2021/02/17/how-to-reverse-a-string-in-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.