myArray = ['1 in','2 in', '3 in']
expected output=
['1','2','3']
but if we add we should able to type ","
I have tried trim
, split
, paresfloat
, filter
methods but it's not working.
myArray = ['1 in','2 in', '3 in']
expected output=
['1','2','3']
but if we add we should able to type ","
I have tried trim
, split
, paresfloat
, filter
methods but it's not working.
Try this solution
let arr = ["1 in" , "2 in", "3 in"]
let filteredArray = arr.map((elt)=>elt.replace( /(?!-)[^0-9.]/g, ""))
console.log(filteredArray)