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