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);
const reversed = array1.reverse();
console.log('reversed:', reversed);
console.log('array1:', array1);
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;
}