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'
]
>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);