Skip to content

Instantly share code, notes, and snippets.

@Shariar-Hasan
Created January 20, 2021 18:20
Show Gist options
  • Save Shariar-Hasan/ecc4ab9e41ad2e2a3a03ce7685093f55 to your computer and use it in GitHub Desktop.
Save Shariar-Hasan/ecc4ab9e41ad2e2a3a03ce7685093f55 to your computer and use it in GitHub Desktop.
two way to reverse a string in Javascript
// 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