demo_met_buffer_compare2.js:
var buf1 = Buffer.from('b'); var buf2 = Buffer.from('c'); var buf3 = Buffer.from('a'); var arr = [buf1, buf2, buf3]; //The array before sorting: console.log(arr); //Sort the array: console.log(arr.sort(Buffer.compare));
C:\Users\My Name>node demo_met_buffer_compare2.js
[ <Buffer 62>, <Buffer 63>, <Buffer 61> ]
[ <Buffer 61>, <Buffer 62>, <Buffer 63> ]