Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove the second number from each string in array

I have an array:

[
  '9.18,50',  '108.78,5',
  '80,2',     '9.18,10',
  '108.78,8', '19.12,10',
  '91.16,5',  '19.12,20'
]

and I would like to map through and create a new variable that will have only the first number in each string. Expected output would be:

[
  '9.18',  '108.78',
  '80',     '9.18',
  '108.78', '19.12',
  '91.16',  '19.12'
]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

try

let date =[
  '9.18,50',  '108.78,5',
  '80,2',     '9.18,10',
  '108.78,8', '19.12,10',
  '91.16,5',  '19.12,20'
];

const result = date.map(x => x.split(',')[0]);

console.log(result);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading