values
function in Node.js Buffer ModuleThe values
function is a member function of Buffer
class in the Node.js Buffer Module. The values
function is called on an instance of Buffer
and returns an Iterator
for the bytes in the instance. The syntax of the values
function is as follows:
buf.values()
values
takes no parameters.
Iterator
for values of buf
.The values
function creates and returns an Iterator
for the values of the buffer buf
.
values
functionThe following code snippet provides an example of how to use the values
function:
const b = Buffer.from('ABCXYZ');for (const v of b.values()) {console.log(v);}
In the above example, b
is a Buffer
instance of length 6
that contains utf-8
encoded bytes for the string ABCXYZ
. The b.values()
function returns an Iterator
, which is stored in v
. In every iteration of the for loop, the value of v
is printed, which is basically an integer value for a byte of buffer b
.
Note: In a
for...of
construct,b.values()
is unnecessary asb
itself would also return a valueIterator
in this case.
Free Resources