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

187
Views
How to flatten a Float32Array in JS?

I have an array filled with Float32Arrays like this:

var arr = [
  new Float32Array([0.3, 0.7, 0.1]),
  new Float32Array([0.2, 0.544, 0.21]),
];

console.log(arr.flat(Infinity));

How do I flatten them to be like this?:

[0.3, 0.7, 0.1, 0.2, 0.544, 0.21]

I have tried use Array.flat(Infinity) but this still leaves the Float32Arrays intact.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

For example

let arr = [
  new Float32Array([0.3, 0.7, 0.1]),
  new Float32Array([0.2, 0.544, 0.21]),
];

arr = arr.map(a => [...a]).flat();

console.log(arr);

about 4 years ago · Juan Pablo Isaza Report

0

const arr = [ new Float32Array([0.3, 0.7, 0.1]), new Float32Array([0.2, 0.544, 0.21])];

const arr3 =  arr.map(float32Array => Array.from(float32Array));
console.log(arr3.flat()); 
/*
^output
[
  0.30000001192092896,
  0.699999988079071,
  0.10000000149011612,
  0.20000000298023224,
  0.5440000295639038,
  0.20999999344348907
]
*/

//rounded to three decimal points
const arr2 =  arr.map(float32Array => Array.from(float32Array).map(float32 => Math.round(float32 * 1000) / 1000));
console.log(arr2.flat()); //--> [0.3, 0.7, 0.1, 0.2, 0.544, 0.21]

about 4 years ago · Juan Pablo Isaza Report

0

Could do -

var arr = [
  new Float32Array([0.3, 0.7, 0.1]),
  new Float32Array([0.2, 0.544,0.21]),
];

console.log(Array.from(arr[0]).concat(Array.from(arr[1])));
about 4 years ago · Juan Pablo Isaza 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!