In this tutorial, we will use an example to show how to convert a javascript array to buffer in node.js
1.Create an array
const testArray = [254, 255, 256, 257, 258];
2.Convert array to buffer
const buffer = Buffer.from(testArray); console.log(buffer);
In this tutorial, we use Buffer.from() function to convert an array to buffer.
Run this code, you will see: