Skip to main content
BufferConstructor.compare - node__buffer.d.ts - Node documentation
method BufferConstructor.compare

Usage in Deno

```typescript import { type BufferConstructor } from "node:node__buffer.d.ts"; ```
BufferConstructor.compare(
buf1: Uint8Array,
buf2: Uint8Array,
):
-1
| 0
| 1
Compares `buf1` to `buf2`, typically for the purpose of sorting arrays of `Buffer` instances. This is equivalent to calling `buf1.compare(buf2)`. ```js import { Buffer } from 'node:buffer'; const buf1 = Buffer.from('1234'); const buf2 = Buffer.from('0123'); const arr = [buf1, buf2]; console.log(arr.sort(Buffer.compare)); // Prints: [ , ] // (This result is equal to: [buf2, buf1].) ```

Parameters

buf1: Uint8Array
buf2: Uint8Array

Return Type

-1
| 0
| 1
Either `-1`, `0`, or `1`, depending on the result of the comparison. See `compare` for details.