Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

nodejs

What is keys() in Node.js Buffer Module?

Hammad Nasir

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.

The keys function in Node.js Buffer Module

The keys function is a member function of Buffer class in the Node.js Buffer Module. The syntax of the keys function is as follows:

buf.keys()

Parameters

keys takes no parameters.

Return Value

  • Returns an Iterator for keys of buf.

Description

The keys function creates and returns an indices Iterator for the keys of the buffer buf.

Example usage of the keys function

The following code snippet provides an example of how to use the keys function:

const b = Buffer.alloc(10, 'x');
for (const k of b.keys()) {
console.log(k);
}

In the above example, b is a Buffer instance of length 10 that is filled with x. The b.keys() function returns an Iterator which is stored in k. In every iteration of the for loop, the value of k is printed, which is basically the index of buffer b.

RELATED TAGS

nodejs

CONTRIBUTOR

Hammad Nasir
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.

Keep Exploring