JS Built-ins
TextEncoderadvanced

TextEncoder.encodeInto β€” read count

πŸ“– Usage Example
const bytes = new TextEncoder().encode('ABC')
new TextDecoder().decode(bytes)  // β†’ 'ABC'

Use TextEncoder/TextDecoder together to round-trip strings through binary buffers.

encodeInto() read Property

encodeInto(source, destination) returns { read, written }.

  • read: number of UTF-16 code units read from the source string

For ASCII text, read === written === source.length.

Challenge: Verify encodeInto('hi', new Uint8Array(10)).read === 2.

πŸ’‘ Hints (1)
  • β€’ For ASCII strings, read === written === string.length.