“JavaScript Sortir nomor” Kode Jawaban

JavaScript Sorts berdasarkan Nilai Numerik

// Sort an array of numbers based on numerical value.
let numbers = [23, 65, 88, 12, 45, 99, 2000]

let sortednumbers = numbers.sort((a, b) => a - b);
//=> [12, 23, 45, 65, 88, 99, 2000]
CodeBaron

Menyortir array dari javascript tertinggi ke terendah

// Sort an array of numbers 
let numbers = [5, 13, 1, 44, 32, 15, 500]

// Lowest to highest
let lowestToHighest = numbers.sort((a, b) => a - b);
//Output: [1,5,13,15,32,44,500]

//Highest to lowest
let highestToLowest = numbers.sort((a, b) => b-a);
//Output: [500,44,32,15,13,5,1]
Arqa

Urutkan nomor dari array di JavaScript

const bignumbers = [66, 58, 81, 444, 92, 9, 6, 13, 2];
const sortedNumbers = bignumbers.sort(function (a, b) {
    return a - b;
})
console.log(sortedNumbers);
//Output: [2, 6, 9, 13, 58,66, 81, 92, 444]
Ariful Islam Adil(Code Lover)

Penyortiran elemen angka Arraray di JavaScript


        
            
        
     let numbers = [0, 1, 2, 3, 10, 20, 30];
numbers.sort((a, b) => a - b);

console.log(numbers);
Sanjay

JS Sort Asendenet

var points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return a-b});
florinrelea

JavaScript Sortir nomor

var numArray = [140000, 104, 99];

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

// Array(3) [ 99, 104, 140000 ]
Marton

Jawaban yang mirip dengan “JavaScript Sortir nomor”

Pertanyaan yang mirip dengan “JavaScript Sortir nomor”

Lebih banyak jawaban terkait untuk “JavaScript Sortir nomor” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya