Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Sort to reverse from an array in javascript

const friends = ["Abir", "Ashik", "Alif", "Alfi", "Shafi", "Kafi"];
const friendsSort = friends.sort();
const friendsReverse = friendsSort.reverse();
console.log(friendsReverse);
//Output: [ 'Shafi', 'Kafi', 'Ashik', 'Alif', 'Alfi', 'Abir' ]
Comment

javascript sort Array descending order

//used arraow functions
const years = [1970, 1999, 1951, 1982, 1963, 2011, 2018, 1922]
const sortYears = arr =>{
  arr.sort((a,b)=>{return b-a})
  return arr
}
console.log(sortYears(years))
// Should print [ 2018, 2011, 1999, 1982, 1970, 1963, 1951, 1922 ]
Comment

PREVIOUS NEXT
Code Example
Javascript :: two decimal places in javascript 
Javascript :: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 
Javascript :: use regex to get urls from string 
Javascript :: difference between slice and splice 
Javascript :: isset js 
Javascript :: vue print date 
Javascript :: powershell json = get value by key 
Javascript :: how to change background image for a webpage 
Javascript :: angular minutes to hour and minutes 
Javascript :: javascript multiples of 3 and 5 
Javascript :: javascript execute string code 
Javascript :: how to go to next page on button click js 
Javascript :: js find first line break in string 
Javascript :: convert a string to a number in js 
Javascript :: Javscript Add days on Date 
Javascript :: set image as background react 
Javascript :: NextJS PWA gitignore 
Javascript :: react native shaddow 
Javascript :: javascript range 
Javascript :: difference between type and method in ajax 
Javascript :: how to reload a module in node.js 
Javascript :: jquery trigger event when scroll to div 
Javascript :: javascript convert minutes to hh mm 
Javascript :: geofencing javascript example 
Javascript :: f string javascript 
Javascript :: You need to authorize this machine using `npm adduser` 
Javascript :: compare and filter two array of object 
Javascript :: wordpress ajax url 
Javascript :: discord.js pick random from array 
Javascript :: javascript from method 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =