How to Reverse a String in JavaScript
Reverse a string in JavaScript using split(), reverse(), and join(), plus a manual loop version and the pitfalls of each approach.
Published September 16, 2026
JavaScript strings have no reverse() method, but arrays do. The usual trick is to split the string into characters, reverse that array, and join it back. This guide shows that approach, a loop-based alternative, and the Unicode trap that breaks the one-liner.
The concept
Strings are immutable in JavaScript, so you never reverse one in place. You build a new string from the characters of the old one in the opposite order.
The one-liner works because split('') turns the string into an array of UTF-16 code units, reverse() flips that array, and join('') glues the pieces together again.
What happens step by step
- split('') turns "hello" into ['h','e','l','l','o']
- reverse() flips the array to ['o','l','l','e','h']
- join('') concatenates it into "olleh"
Practical examples
The one-liner
const reverse = (s) => s.split('').reverse().join('')
reverse('hello') // 'olleh'Spread operator (handles emoji)
split('') cuts surrogate pairs in half. The spread operator iterates by code point, so emoji survive.
const reverse = (s) => [...s].reverse().join('')
reverse('aπb') // 'bπa'A plain loop
Useful in interviews or when you want no intermediate array.
function reverse(s) {
let out = ''
for (let i = s.length - 1; i >= 0; i--) out += s[i]
return out
}Common mistakes
- Calling str.reverse() directly β strings have no such method.
- Using split('') on text with emoji or combining accents, which scrambles them.
- Forgetting that reverse() on an array mutates it; copy first if you still need the original.
Key takeaways
- split β reverse β join is the idiomatic solution.
- Use [...str] for Unicode-safe reversing.
- Strings are immutable; you always produce a new one.
FAQ
Why does my emoji look broken after reversing?
split('') separates the two UTF-16 halves of an emoji. Use [...str] or Array.from(str) instead.
Which method is fastest?
A plain loop is usually fastest for very long strings, but the difference is negligible for normal input.