Skip to main content

getMemory

Estimates the memory usage of a value in bytes and returns a human-readable string representing the size.

Parameters

ParameterTypeOptionalDefaultDescription
valueanyfalseThe value whose memory usage is to be estimated. This can be an Object, string, number, boolean, or an Array.

Returns

string

Example

getMemory("John"); // "8.00 Bytes"
getMemory(12); // "8.00 Bytes"
getMemory(true); // "4.00 Bytes"
getMemory(["John", 12]); // "16.00 Bytes"
getMemory({ name: "John", age: 12 }); // "16.00 Bytes"