How to convert array in string to array with floats in JavaScript

1 Answer

0 votes
const str = "['3.14', '-2.89', '7.13', '12.45']";

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


  
  
/*
run:
  
[3.14, -2.89, 7.13, 12.45]
  
*/

 



answered Jun 6, 2022 by avibootz

Related questions

...