Buffer.byteLength()

Class Method: Buffer.byteLength(string[, encoding])

Returns the actual byte length of a string. This is not the same as String.prototype.length since that returns the number of characters in a string.

Example:

const str = '\u00bd + \u00bc = \u00be';

console.log(`${str}: ${str.length} characters, ` +
            `${Buffer.byteLength(str, 'utf8')} bytes`);

// ½ + ¼ = ¾: 9 characters, 12 bytes

When string is a Buffer/DataView/TypedArray/ArrayBuffer, returns the actual byte length.

Otherwise, converts to String and returns the byte length of string.

doc_Nodejs
2016-04-30 04:37:30
Comments
Leave a Comment

Please login to continue.