Řazení seznamu js

Příklady kódu

46
0

N

var points = [40, 100, 1, 5, 25, 10];
points.sort((a,b) => a-b)

4
0

N

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

N


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

console.log(numbers);
3
0

N

const unsorted = ['d', 'd', 'h', 'r', 'v', 'z', 'f', 'c', 'g'];
const sorted = unsorted.sort();

console.log(sorted);
//["c", "d", "d", "f", "g", "h", "r", "v", "z"]


const unsortedNums = [45, 56, 3, 3, 4, 6, 7, 45, 1];
const sortedNums = unsortedNums.sort((a, b) => {
	return a - b;
});

console.log(sortedNums);
//[1, 3, 3, 4, 6, 7, 45, 45, 56]
1
0

N

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

N

const months = ['March', 'Jan', 'Feb', 'Dec'];
months.sort();
console.log(months);
// expected output: Array ["Dec", "Feb", "Jan", "March"]

V jiných jazycích

Tato stránka je v jiných jazycích

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................