Phương thức sort() của đối tượng Typed Array sắp xếp các phần tử theo thứ tự tăng dần và trả về mảng đã sắp xếp.
Cú pháp
typedArray.sort()
Ví dụ
<html> <head> <title>Ví dụ JavaScript</title> </head> <body> <script type="text/javascript"> var typedArray = new Int32Array([11, 5, 13, 4, 15, 3, 17, 2, 19, 8 ]); document.write("Mảng gốc: " + typedArray); document.write("<br>"); var resultantArray = typedArray.sort(); document.write("Mảng đã sắp xếp: " + resultantArray); </script> </body> </html>
Kết quả
Mảng gốc: 11,5,13,4,15,3,17,2,19,8 Mảng đã sắp xếp: 2,3,4,5,8,11,13,15,17,19