How to Reverse a String in JavaScript
Reverse a string with the split–reverse–join one-liner, understand why each step is needed, and handle emoji and accented characters correctly.
Overview
JavaScript strings have no built-in reverse() method — that method belongs to arrays. So the standard recipe is to turn the string into an array of characters, reverse the array, and join it back into a string. One line does it, and the reason it works is worth understanding because it explains the edge cases too.
// the answer up front — the classic ASCII-only form you'll see in most tutorials
const reversed = 'hello'.split('').reverse().join('');
console.log(reversed); // 'olleh' — fine for plain text, unsafe for emoji
Steps
1. Split the string into characters
split('') breaks the string into an array with one element per character. This is the step that lets you use array methods on text, since the string itself is immutable and has nothing to reverse in place.
const chars = 'hello'.split('');
console.log(chars); // ['h', 'e', 'l', 'l', 'o']
2. Reverse the array
reverse() flips the array in place and returns it. Because we're working on the throwaway array from step 1, mutating it is harmless — the original string is untouched, as strings always are.
console.log(['h', 'e', 'l', 'l', 'o'].reverse()); // ['o', 'l', 'l', 'e', 'h']
3. Join the characters back into a string
join('') glues the array elements back together with no separator, giving you the reversed string. Chained together, the three calls read as a single, clear pipeline.
const reversed = 'hello'.split('').reverse().join('');
console.log(reversed); // 'olleh'
4. Handle emoji and accents correctly
split('') cuts on UTF-16 code units, which breaks characters made of two units — most emoji, and some accented letters — into halves. Splitting with the spread operator or Array.from() respects whole characters, so use that when the text isn't plain ASCII.
// naive split can mangle multi-unit characters
const safe = [...'ab😀'].reverse().join('');
console.log(safe); // '😀ba' — emoji kept intact
Put together, [...str].reverse().join('') is the version to remember, and it's worth seeing why each link in the chain is necessary. Spreading (or split('')) is what gets you from an immutable string to a mutable array of characters; reverse() is an array method, so it only works once you are holding an array; and join('') collapses that array back into a string with no separator between the characters. Drop any one step and you are either unable to reverse — strings have no reverse() of their own — or left holding an array where you wanted a string.
Runnable example
The complete one-liner, runnable — edit the input and watch the original survive:
Common pitfalls
There is no faster built-in shortcut: reversing is inherently O(n) because every character has to move. The split–reverse–join pipeline is the idiomatic, readable choice, and a manual for loop building the string backwards is no faster — only longer:
function reverseLoop(str) {
let out = '';
for (let i = str.length - 1; i >= 0; i--) out += str[i];
return out;
}
console.log(reverseLoop('hello')); // 'olleh'
Frequently asked questions
Why doesn't JavaScript have a string reverse() method?
str.split('').reverse().join(''), or [...str].reverse().join('') for full Unicode safety.How do I reverse a string with emoji correctly?
[...str].reverse().join(''). Unlike split(''), spreading iterates by whole characters, so multi-code-unit characters like emoji are not split in half.