Open this example in the interactive library
Source code
const s = "café ☕";
console.log({ units: s.length, bytes: new TextEncoder().encode(s).length });
Sample output
{ units: 6, bytes: 9 }
Open this example in the interactive library
const s = "café ☕";
console.log({ units: s.length, bytes: new TextEncoder().encode(s).length });
{ units: 6, bytes: 9 }