Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

406
Views
Convert Uint8Array to Array in Javascript

I have Uint8Array instance that contains binary data of some file.
I want to send data to the server, where it will be deserialized as byte[].
But if I send Uint8Array, I have deserialization error.

So, I want to convert it to Array, as Array is deserialized well.
I do it as follows:

    function uint8ArrayToArray(uint8Array) {
        var array = [];

        for (var i = 0; i < uint8Array.byteLength; i++) {
            array[i] = uint8Array[i];
        }

        return array;
    }

This function works fine, but it is not very efficient for big files.

Question: Is there more efficient way to convert Uint8Array --> Array?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use the following in environments that support Array.from already (ES6)

var array = Array.from(uint8Array)

When that is not supported you can use

var array = [].slice.call(uint8Array)
over 4 years ago · Santiago Trujillo Report

0

There is a method of Uint8Array using the prototype (but it only supported by Firefox and Chrome):

TypedArray.prototype.entries() --> it returns a array.

Check it out: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/entries

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!