copy typed array to an array

Posted on
  • What is the best solution to copy data from an typed Array (Uint8Array, ...) to an Array ?
    Mozilla recommends Array.from(typedArray) or if .from is not available.
    var typedArray = new Uint8Array([1, 2, 3, 4]),

    normalArray = Array.prototype.slice.call(typedArray);
    

    Both are not available on Espruino (yet?)
    Copy data in a loop is very time (and memory ?) consuming.

  • I think you could probably repurpose Array.slice?

    [].slice.call(uint8array,0)
    

    That'll probably be about as speedy and clean as you can get?

  • Great, that works like crazy.
    Thanks a lot for this unbelievable fast response.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

copy typed array to an array

Posted by Avatar for JumJum @JumJum

Actions