revers js code example

Example 1: reversing an array in js

var arr=[1,2,5,6,2]
arr.reverse()

Example 2: reverse array javascript

var rev = arr.reverse();

Example 3: js reverse

const array1 = ['one', 'two', 'three'];
console.log('array1:', array1);
//["one", "two", "three"]

const reversed = array1.reverse();
console.log('reversed:', reversed);
//["three", "two", "one"]

// Careful: reverse is destructive -- it changes the original array.
console.log('array1:', array1);
//["three", "two", "one"]

Example 4: Reversing an array

#include<iostream>
using namespace std;
int main()
{
	int Arr[100],n,temp,i,j;
	cout<<"Enter number of elements you want to insert ";
	cin>>n;
	for(i=0;i<n;i++)
	{
		cout<<"Enter element "<<i+1<<":";
		cin>>Arr[i];
	}
	for(i=0,j=n-1;i<n/2;i++,j--)
	{
		temp=Arr[i];
		Arr[i]=Arr[j];
		Arr[j]=temp;
	}
	cout<<"\nReverse array"<<endl;
	for(i=0;i<n;i++)
		cout<<Arr[i]<<" ";
	return 0;
}