I had to resort to doing this at one point:
var bytes = [ 1, 0, 1, 0, 0, 0, 1, 0 ]
var integer = parseInt(bytes.join(''), 2)
However, I am wondering if there is a more optimal/proper way of doing this in JavaScript rather than converting it to a string and parsing it. In addition to asking how to do the above and turn it into an integer, I would also like to know how to turn it into a bytearray. Something like this:
var bytes = [ 1, 0, 1, 0, 0, 0, 1, 0 ]
var bytearray = new Uint8Array(bytes)
var integer = bytearray.toInteger()