Reverse string in JavaScript

Published on September 12th, 2019

javascript icon

You have string to reverse? Easy, just install yet another package from npm! I’m kidding, there is an easier way with some array magic.

const str = 'Hey, whats up?'

This expression might look a bit confusing but all it does is convert string to array of characters, reverses it and joins back in string.

const reversed = [...str].reverse().join('')

// value: ?pu stahw ,yeH

Enjoy your reversed string!