performance - How to sort typed arrays in javascript? -


For example, I have typed an array like this:

  var a = New Int32Array ([3,8,6,1,6,9]);  

When I try to call a.sort () , then it does not work.

What's the best way to type arrays? Regarding performance, can we sharpen the arrays typed in comparison to regular arrays?

JavaScript array methods are defined as such that they are array-like < / Em> objects, only you can use the array of the original code:

  Array.prototype.sort.call (a , Function (a, b) {return a - b;});  

A custom callback is required because JS bases the values ​​by default by default. See also.


Comments