4 examples of 'javascript string to char array' in JavaScript

Every line of 'javascript string to char array' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
380function str2char( str ) {
381 var result = new Array( str.length );
382 for ( var i=0; i<str.length; i++ ) {
383 result[i] = str.charCodeAt( i );
384 }
385 return result;
386}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

56encoder.CHARARRAY = function CHARARRAY(v) { return v.split('').map(function(v) { return v.charCodeAt(0); }); };
58function stringToArrayBuffer(str: string): Uint8Array {
59 const asArray = new Uint8Array(str.length)
60 let arrayIndex = 0
61 for (let i = 0; i < str.length; i++) {
62 const codePoint = (String.prototype as { codePointAt: (i: number) => number }).codePointAt
63 ? (str as { codePointAt: (i: number) => number }).codePointAt(i)
64 : codePointAtPolyfill(str, i)
65 asArray[arrayIndex++] = codePoint & 0xff
66 }
67 return asArray
68}
209function characterToEcmaScriptEscape (character)
210{
211 let num = character.codePointAt (0);
212 let hex = num.toString (16).toUpperCase ();
213 return `\\u{${hex}}`;
214}

Related snippets