Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ascending and descending val in array using js

numArray.sort((a, b) => a - b); // For ascending sort
numArray.sort((a, b) => b - a); // For descending sort
Comment

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 ascending and descending

// ascending and discending for number
const arr1 = [21, 2100, 2, 35000];
const arr2 = [21, 2100, 2, 35000];

let ascN = arr1.sort((f, s) => f - s);
let dscN = arr2.sort((f, s) => s - f);

// ascending and discending for string
const arr3 = ['21', '2100', '2', '35000'];
const arr4 = ['21', '2100', '2', '35000'];

let ascS = arr3.sort((f, s) => f.length - s.length);
let dscS = arr4.sort((f, s) => s.length - f.length);
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

sort array descending

testsSortedByNome = tests.sort((a, b) => (a.nome > b.nome ? -1 : 1));
testsSortedByCognome = tests.sort((a, b) => (a.cognome > b.cognome ? -1 : 1));
Comment

array sorting descending

employees.sort((a, b) => b.age - a.age);

employees.forEach((e) => {
    console.log(`${e.firstName} ${e.lastName} ${e.age}`);
});
Code language: JavaScript (javascript)
Comment

PREVIOUS NEXT
Code Example
Javascript :: move_uploaded_file equivalent in js 
Javascript :: repeater javascript 
Javascript :: javascript array every 
Javascript :: loading indicator react native 
Javascript :: nested object 
Javascript :: add image to center in canvas 
Javascript :: find leap year javascript 
Javascript :: javascript detect video change to muted 
Javascript :: deletenode javascript 
Javascript :: javascript$.4908BEAMpacidE 
Javascript :: rest object javascript 
Javascript :: samesite cookies/console.log 
Javascript :: load content on user language in javascript 
Javascript :: javascript loop through delimited string 
Javascript :: traversing 2d array javascript 
Javascript :: adonis model inheritance 
Javascript :: sample asynchronous 
Javascript :: sanitize html before storing to db in js 
Javascript :: conditional ternary statement only one return 
Javascript :: js num to str 
Javascript :: How to append variable with anchor element href link in Angularjs 
Javascript :: angularjs How to populate ng-style with object of CSS 
Javascript :: Relaxed "angularjs" style expression parsing missing in vue 
Javascript :: Get the childrens of an element in react native using useRef 
Javascript :: settimeout and create directory nodejs 
Javascript :: Using javascript code in Jade views - if(variable) shows undefined instead of passing 
Javascript :: No enum constant datepicker react native 
Javascript :: react state based router 
Javascript :: javascript server side 
Javascript :: add defer in tag manager 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =