Skip to main content Accessibility Feedback

Reversing the order of an array with vanilla JavaScript

It’s incredibly easy to reverse the order of an array’s values with vanilla JavaScript, thanks to the Array.reverse() method.

var sandwiches = ['turkey', 'tuna', 'italian', 'chicken salad'];
sandwiches.reverse();

// returns ["chicken salad", "italian", "tuna", "turkey"]
console.log(sandwiches);

This works in all moderns browsers and back to at least IE6.


🚀 Make 2018 the year you master JavaScript! My pocket guides and mini courses are short, focused, and made for beginners. You can do this!

Have any questions or comments about this post? Email me at chris@gomakethings.com or contact me on Twitter at @ChrisFerdinandi.

Get Daily Developer Tips