Languages
[Edit]
EN

JavaScript - reverse string (English letters)

4 points
Created by:
elmer
646

In this short article, we would like to show you how reverse strings using JavaScript.

In practice string reversion problem is very comples when we work on emojis, surrogate characters, Asian characters, etc. Some solutions for that kind of strings reversion was shown in this article.

 

In the below you can find different solutions.

1. split-reverse-join example

Edit

Warning: this solutuion doesn't work with all emojis and Asian characters.

Output:

2. Reverse string with iteration example

Edit

2.1. for...of solutuion

Edit

This solution should be used when we work on more comples unicode characters like emoji.

Warnings:

  • this solution works under ES6+,
  • this solutuion doesn't work with all emojis and Asian characters.

2.2. classic for solution

Edit

Warning: this solutuion doesn't work with all emojis and Asian characters.

3. String.prototype.reverse method prototype

Edit

Note: in this case String object is extended of new reverse method.

Warning: this solutuion doesn't work with all emojis and Asian characters.

Output:

 

See also

Edit
  1. JavaScript - reverse string that contains emoji, surrogate characters and Asian characters

Alternative titles

  1. JavaScript - how to reverse string with English letters?
  2. JavaScript - reverse text (English letters)
  3. JavaScript - how to reverse text with English letters?
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - reverse string

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join