Created
January 20, 2021 18:20
-
-
Save Shariar-Hasan/ecc4ab9e41ad2e2a3a03ce7685093f55 to your computer and use it in GitHub Desktop.
two way to reverse a string in Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using a loop | |
var str = "i am a javascript programmer"; | |
var reverseString = "" | |
for(var i = str.length ; i > 0; i--) | |
{ | |
reverseString += str[i-1]; | |
} | |
console.log(reverseString); | |
// using methods | |
console.log(str.split("").reverse().join("")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment