I'm passing in a Buffer from the client-side using the binaryjs module in node js. This buffer contains a pipe delimited string that I eventually parse on the server.
On the client side I convert a String to a Uint8Array. My String looks something like this:
var stringToConvert = 'A_1_22|B_2_33|C_3_44';
When this Uint8Array is passed to my server, it's received as a Buffer. I first chunk together the Buffer into an array:
var parts = [];
// ...
// as data is received:
parts.push(data);
When I have all the data streamed, I convert this array to a String and split by "|":
var arrayString = parts.toString().split("|");
This gets me the desired array output:
arrayString = ['A_1_22', 'B_2_33', 'C_3_33'];
I then iterate over this arrayString and split again by "_".
for(var i = 0; i < arrayString.length; i++)
{
var thisArray = arrayString[i].split("_");
// ...
The problem occurs when I try to iterate over thisArray to convert the second and third values to ints:
var intVal1 = parseInt(thisArray[1]); // returns NaN
var intVal2 = parseInt(thisArray[2]); // returns NaN
console.log(typeof thisArray[1]); // returns string
Running the identical code on the client side properly converts the strings to ints. Not sure what I'm missing here?