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

1 Answer

0 votes
const str = "['13.14', '-32.89', '47.13', '512.45']";

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


  
  
/*
run:
  
[13.14, -32.89, 47.13, 512.45] 
  
*/

 



answered Jun 6, 2022 by avibootz

Related questions

...