THE WORLD'S LARGEST WEB DEVELOPER SITE

Node.js Buffer.byteLength() Method

❮ Buffer Module


Example

Check the length of a buffer object:

var buf = Buffer.alloc(15);
var len = Buffer.byteLength(buf);
console.log(len);
Run example »

Definition and Usage

The Buffer.byteLength() method returns the length of a specified string object, in bytes.


Syntax

 Buffer.byteLength(string, encoding);

Parameter Values

Parameter Description
string Required. Specifies the object to calculate the length of. Supported types are:
String
Buffer
TypedArray
DataView
ArrayBuffer
encoding Optional. If the object is a string, this parameter specified its encoding. Default encoding is "utf8"

Technical Details

Return Value: The number of bytes in the specified object
Node.js Version: 0.1.90

More Examples

Example

Return the number of bytes in the string "abc":

var len = Buffer.byteLength('abc');
console.log(len);
Run example »

❮ Buffer Module