Convert string to byte array - Node.js String

Node.js examples for String:Base 64

Description

Convert string to byte array

Demo Code


function stringToByteArray(s){

    // Otherwise, fall back to 7-bit ASCII only
    var result = new Uint8Array(s.length);
    for (var i=0; i<s.length; i++){
        result[i] = s.charCodeAt(i);/* w ww. ja  v  a 2s . co  m*/
    }
    return result;
}

Related Tutorials