Javascript BigInt64Array sort()

Introduction

The Javascript BigInt64Array sort() method sorts the elements of a typed array numerically.

It returns the sorted typed array.

This method works the same as Array.prototype.sort(), except that sorts the values numerically instead of as strings.

BigInt64Array.sort([compareFunction])
Parameter Optional Meaning
compareFunctionOptional Specifies a function that defines the sort order.

Unlike plain Arrays, a compare function is not required to sort the numbers numerically.

Regular Arrays require a compare function to sort numerically:

let numbers = new BigInt64Array([40n, 1n, 5n, 200n]);
numbers.sort();//from  www  .  j  av  a 2  s  . c o  m
numbers = [40n, 1n, 5n, 200n];
numbers.sort();
console.log(numbers);

numbers.sort((a, b) => a - b); // compare numbers
console.log(numbers);



PreviousNext

Related