Class Method: Buffer.byteLength(string[, encoding])
-
string<String> | <Buffer> | <TypedArray> | <DataView> | <ArrayBuffer> -
encoding<String> Default:'utf8' - Return: <Number>
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 bytesWhen string is a Buffer/DataView/TypedArray/ArrayBuffer, returns the actual byte length.
Otherwise, converts to String and returns the byte length of string.
Please login to continue.