Open this example in the interactive library
Source code
import { Buffer } from "node:buffer";
console.log([...Buffer.from([1, 2, 3, 4]).swap16()]);
Sample output
[ 2, 1, 4, 3 ]

Open this example in the interactive library
import { Buffer } from "node:buffer";
console.log([...Buffer.from([1, 2, 3, 4]).swap16()]);
[ 2, 1, 4, 3 ]