How to convert comma separated string to numeric array in JavaScript

1 Answer

0 votes
const str = '5,7,81,25,2,50,99';

const arr = str.split(',').map(element => {
  	return Number(element);
});

console.log(arr);
 
 
 
 
 
/*
run:
 
[5, 7, 81, 25, 2, 50, 99]
 
*/

 



answered Apr 11, 2022 by avibootz
...