JavaScript Array.reverse() Method Example

📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.

🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.

▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube

▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube

The reverse() method reverses the order of the elements in an array.

Syntax

a.reverse()
Return value - The reversed array.

Examples

Example 1: Reverse a given string array

var array1 = ['one', 'two', 'three']; console.log('array1: ', array1); // expected output: Array ['one', 'two', 'three'] var reversed = array1.reverse(); console.log('reversed: ', reversed); // expected output: Array ['three', 'two', 'one'] /* Careful: reverse is destructive. It also changes the original array */ console.log('array1: ', array1); // expected output: Array ['three', 'two', 'one']

Example 2: Reversing the integer elements in an array

const a = [1, 2, 3]; console.log(a); // [1, 2, 3] a.reverse(); console.log(a); // [3, 2, 1]

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare