Web APIs

TextEncoder.prototype.encodeInto()

Try the free JavaScript compiler

Encodes complete characters into a supplied byte view and reports consumed code units and written bytes.

Formal Syntax & Structure

javascript syntaxjavascript
encoder.encodeInto(source, destination)

Parameters & Attributes

NameTypeDescription
sourcestringSource text.
destinationUint8ArrayDestination byte view.

Return Value

object

Encodes complete characters into a supplied byte view and reports consumed code units and written bytes.

Working Example

Example Snippetjavascript
(async () => {const dst=new Uint8Array(2);const r=new TextEncoder().encodeInto("Aé",dst);console.log(r.read,r.written,JSON.stringify([...dst]));})()
JavaScript Reference