Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

What is the length property in Buffer module of Node.js?

Rukhshan Haroon

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

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:

%0 node_1625727698073 0 node_1 1 node_2 2 node_3 3 node_1625727684280 4
Buffer of 5 integers

Syntax

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.

Return value

It returns the size or length of the buffer.

Example

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);

RELATED TAGS

CONTRIBUTOR

Rukhshan Haroon
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring