sort()
メソッドは、TypedArray 内で要素をソートして、その TypedArray を返します。このメソッドのアルゴリズムは Array.prototype.sort()
と同じものです。 TypedArray とは TypedArray の型 のどれかを表します。
構文
typedarray.sort([compareFunction])
パラメータ
compareFunction
Optional- ソート順を定義する関数を指定します。
戻り値
ソートされた TypedArray。
例
他の例については、Array.prototype.sort()
を参照して下さい。
var numbers = new Uint8Array([40, 1, 5, 200]); numbers.sort(); // Uint8Array [ 1, 5, 40, 200 ] // A compare function is not required as in the case of Array // to sort the numbers numerically. var numbers = [40, 1, 5, 200]; numbers.sort(); // The elements are sorted as strings. // [1, 200, 40, 5] function compareNumbers(a, b) { return a - b; } numbers.sort(compareNumbers); // [ 1, 5, 40, 200 ]
仕様
仕様 | ステータス | コメント |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) TypedArray.prototype.sort の定義 |
標準 | 最初の定義。 |
ECMAScript 2017 Draft (ECMA-262) TypedArray.prototype.sort の定義 |
ドラフト |
ブラウザ実装状況
機能 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
基本サポート | (有) | 46 (46) | ? | (有) | ? |
機能 | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
基本サポート | ? | ? | 46.0 (46) | ? | ? | ? |