The length
property in the Buffer module of Node.js denotes the number of data-elements stored inside a buffer.
The length of the following buffer is 5, as it contains 5 values:
To access the length property of a buffer, the following syntax is used:
buffer.length
The identifier buffer
is the name of a pre-allocated buffer.
It returns the size or length of the buffer.
The following program allocates a buffer filled with a custom string using the Buffer.from
function. The identifier for it is buffer
. The console.log
function is used to print the value of the length
property of buffer
on the console:
var buffer = Buffer.from('Educative');console.log(buffer.length);
Free Resources