[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/sort [Back]  [Original]

TypedArray.prototype.sort() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

TypedArray.prototype.sort()

Baseline

20169

sort() TypedArray (in-place) Array.prototype.sort()

const uint8 = new Uint8Array([40, 10, 50, 20, 30]);
uint8.sort();

console.log(uint8);
// : Uint8Array [10, 20, 30, 40, 50]

js
sort()
sort(compareFn)

compareFn

a

undefined

b

2 undefined

  • a b
  • a b
  • 0 NaN a b

(a, b) => a - b

(in-place)

Array.prototype.sort()

sort()

Array.prototype.sort()

js
let numbers = new Uint8Array([40, 1, 5, 200]);
numbers.sort();
// Uint8Array [ 1, 5, 40, 200 ]
// 
// 

// 
numbers = [40, 1, 5, 200];
numbers.sort();
// [1, 200, 40, 5]

numbers.sort((a, b) => a - b); // 
// [ 1, 5, 40, 200 ]

ECMAScript 2027 LanguageSpecification
# sec-%typedarray%.prototype.sort


Web Proxy Viewer  |  New URL  |  Original Page