How to convert array in string to array with floats in Node.js

1 Answer

0 votes
const str = "['133.14', '-312.89', '247.13', '5512.45']";

const numbers = str.match(/-?\d+(?:\.\d+)?/g).map(Number)
  
console.log(numbers);


  
  
/*
run:
  
[ 133.14, -312.89, 247.13, 5512.45 ]
  
*/

 



answered Jun 6, 2022 by avibootz

Related questions

1 answer 111 views
2 answers 244 views
1 answer 138 views
1 answer 145 views
...