Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
where is Buffer.forEach specified?

I know that I can iterate over a Buffer with:

for( const b of buffer ){
  console.log(b);
}

But I noticed I can also call .forEach, .map, etc.

$ node
> const buffer = new Buffer.from([1,2,3]);
undefined
> buffer.forEach( b => console.log( b ) );
1
2
3
undefined
> buffer.map( b => 'value:' + b.toString() ).toString();
'\x00\x00\x00'

Apparently these methods are not specified on the node.js Buffer page, and also I don't understand why it behaves as it does (e.g. '\x00\x00\x00').

Where are the methods .forEach, .map, etc. on the Buffer type specified ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Right from the Nodejs Buffer doc.

Buffer instances are also JavaScript Uint8Array and TypedArray instances. All TypedArray methods are available on Buffers.

And, you can see all sorts of methods on a TypedArray including the ones you mention in your question.

If you go look at the implementation of the nodejs Buffer object, you will see that it is made from something they refer to as a FastBuffer. That inherits a bunch of things from Uint8Array which is likely where the methods you asked about come from:

class FastBuffer extends Uint8Array 

And, there is also a function used to populate the prototype with all sorts of additional methods here.


And, for a little diagnostics, if you run this code in nodejs:

let b = Buffer.alloc(100);

console.log(`Buffer instanceof Buffer: ${b instanceof Buffer}`);
console.log(`Buffer instanceof Uint8Array: ${b instanceof Uint8Array}`);

you will see this output:

Buffer instanceof Buffer: true
Buffer instanceof Uint8Array: true

And, then if you walk the prototype chain with this:

let proto = Buffer.prototype;
while (proto) {
    console.log(proto.constructor.name);
    proto = Object.getPrototypeOf(proto);
}

You will get this output that shows the class inheritance:

Buffer
Uint8Array
TypedArray
Object
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!