Want to reverse a string in place in JavaScript? As long as you’re dealing with simple ASCII characters, and you’re happy to use built-in functions, this will work:
1 2 3 | function reverse(s){ return s.split("").reverse().join(""); } |
If you need a solution that supports UTF-16 or other multi-byte characters, be aware that this function will give invalid unicode strings, or valid strings that look funny. You might want to consider this answer instead.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.