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

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

js sort numbers descending order

// Sort Numbers in Descending Order
function sortDescending(num) {
	return Number(num.toString().split('').sort((a, b) => b - a).join(''));
//or: return parseInt(num.toString().split('').sort().reverse().join(''));
}

console.log(sortDescending(123)); // 321
console.log(sortDescending(1254859723)); // 9875543221
Comment

javascript sort numbers descending

var numArray = [140000, 32, 12, 63323, 104, 99];

numArray.sort(function(a, b) {
  return b - a;
});

// Array(6) [ 140000, 63323, 104, 99, 32, 12 ]
Comment

PREVIOUS NEXT
Code Example
Javascript :: Return certain fields with populate from mongoose 
Javascript :: react dictionary key value avec 2 variable 
Javascript :: altv rpc 
Javascript :: prevent form submission on onsubmit function calls 
Javascript :: body click function removeclass 
Javascript :: insert image into datatable 
Javascript :: target url javascript 
Javascript :: Vuejs watch for nested data 
Javascript :: jboss session expiration time 
Javascript :: js clear dictionary 
Javascript :: all ajaxcomplete event 
Javascript :: react-router-dom 
Javascript :: js insert emoji 
Javascript :: how to create a random number generator in javascript 
Javascript :: out of memory gc overhead limit exceeded. react native 
Javascript :: remove underline from hyperlink react 
Javascript :: js check if string is number 
Javascript :: node js variables in string 
Javascript :: mocha should throw error 
Javascript :: find all checkbox inside div jquery 
Javascript :: how to change color of font in js 
Javascript :: javascript console group 
Javascript :: last week date js 
Javascript :: axios.post request with custom headers 
Javascript :: js random in range 
Javascript :: icon refresh material ui 
Javascript :: checkbox event listener 
Javascript :: react run useeffect only once 
Javascript :: Warning: Prop `className` did not match. Client and server rendered different classes . 
Javascript :: windows terminal vai kill all node js port 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =