How to insert array into a string in Node.js

2 Answers

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

const str = '[' + arr + ']';
  
console.log(str);
console.log(typeof str);

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


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

 



answered Jun 6, 2022 by avibootz
0 votes
const arr = ['133.14', '-312.89', '247.13', '15512.45'];
 
const str = "" + arr + "";
   
console.log(str);
console.log(typeof str);
 
// test
const numbers = str.match(/-?\d+(?:\.\d+)?/g).map(Number)
console.log(numbers);
 
 
   
   
   
/*
run:
   
133.14,-312.89,247.13,15512.45
string
[ 133.14, -312.89, 247.13, 15512.45 ]

*/

 



answered Jun 6, 2022 by avibootz

Related questions

1 answer 119 views
1 answer 128 views
1 answer 160 views
1 answer 128 views
...