以下のコードで文字列をUTF-16コードユニットの配列に変換できます。
Array.from("🍎🍊😁", s => Array.from({length: s.length}, (_, i) => s.charCodeAt(i))) // Array(3) [ [ 55356, 57166 ], [ 55356, 57162 ], [ 55357, 56833 ] ] Array.from("🍎🍊😁", s => Array.from({length: s.length}, (_, i) => s.charCodeAt(i))).flat() // Array(6) [ 55356, 57166, 55356, 57162, 55357, 56833 ]
関数にしておくと便利かもしれません。
const getUTF16CharPointsFromString = (source) => { if (typeof source != "string") return undefined; return Array.from(source, s => Array.from({length: s.length}, (_, i) => s.charCodeAt(i))) } getUTF16CharPointsFromString("🍎🍊😁") // Array(3) [ [ 55356, 57166 ], [ 55356, 57162 ], [ 55357, 56833 ]] getUTF16CharPointsFromString("🍎🍊😁").flat() // Array(6) [ 55356, 57166, 55356, 57162, 55357, 56833 ]