Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Using the reverse method to Reverse an Array

var arr = [1,2,3,4];
arr.reverse();
console.log(arr);
Comment

reverse () method to reverse the array

var arrayReverse = ["s", "o", "f", "t", "h", "u", "n", "t"]. reverse ();
["t", "n", "u", "h", "t", "f", "o", "s"]
Comment

how to make a arr reverse function

let mainFunction=(arr)=>{

if(arr.length %2 != 0 ){
return false

}
else{
for (let i=0 ; i < arr.length /2 ; ++i ){
let temp=arr[i];
arr[i]=arr[i + arr.length /2]
arr[i+ arr.length /2]= temp


}

}
return arr
}


console.log(mainFunction([1,2,4,6]))


//output
// [4,6,1,2]
Comment

PREVIOUS NEXT
Code Example
Javascript :: rxjs coding example 
Javascript :: reverse array recursion javascript 
Javascript :: javascript javascript javascript javascript javascript 
Javascript :: express delete session variable 
Javascript :: star print in javascript 
Javascript :: convert excel date to javascript date 
Javascript :: javascript get last emlement array 
Javascript :: convert javascript date into excel date 
Javascript :: component navigation without changin the url react router 
Javascript :: sum all odd in binary search tree recursion javascript 
Javascript :: convert number to indian rupee format in javascript 
Javascript :: can you get reinfected with the coronavirus 
Javascript :: esx global error 
Javascript :: Material-ui alarm icon 
Javascript :: Tushar Jadhav 
Javascript :: last underscore 
Python :: print red in python 
Python :: drop last row pandas 
Python :: pandas see all columns 
Python :: get external ip python 
Python :: python datetime tomorrow date 
Python :: python print time 
Python :: python get utc time 
Python :: clear outpur jupyter 
Python :: add text toimage cv2 
Python :: how to find rows with missing data in pandas 
Python :: conda install xgboost 
Python :: get screen size python 
Python :: matplotlib bar chart from dictionary 
Python :: auto datetime in django models 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =