miktam / sizeof

Get size of a JavaScript object
MIT License
301 stars 45 forks source link

Weird Behaviour with arrays #87

Open geo-systems opened 1 year ago

geo-systems commented 1 year ago

I'm on Node JS 18.12.1 and I'm seeing the following behaviour:

const sizeof = require('object-sizeof')
> sizeof(["a","b","c","d","e"])
21
> sizeof("abcde")
20
> sizeof(["abcde"])
9

Why is an array of a string smaller than the string itself?

Why is an array of letters 1 byte bigger than the string? Shouldn't they be the same? Or may be the array is slightly bigger due to some reference?