How to extract multiple floats from a string of floats in Node.js

1 Answer

0 votes
const str = "3.5001 -46.81 76.847 -563.901 6014.8004";
const tokens = str.split(' ');
const floats = [];

for (let i = 0; i < tokens.length; i++) {
  const f = parseFloat(tokens[i]);
  console.log(f);
  floats.push(f);
}


 
/*
run:
     
3.5001
-46.81
76.847
-563.901
6014.8004
      
*/

 



answered Jul 28, 2025 by avibootz
...