JS Built-ins
TextEncoderintermediate

TextEncoder.encodeInto β€” written count

πŸ“– Usage Example
const dest = new Uint8Array(10)
const { read, written } = new TextEncoder().encodeInto('Hello', dest)
// read: 5, written: 5

encodeInto() writes bytes into an existing buffer and reports how many were read/written.

encodeInto() Method

encodeInto(source, destination) writes UTF-8 bytes into a pre-allocated Uint8Array and returns { read, written }.

  • written: number of bytes written into the destination

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

πŸ’‘ Hints (1)
  • β€’ encodeInto returns a TextEncoderEncodeIntoResult with read and written.