I have an array:
let array = ['john,1','mars,2','marry,3',' , '];
I want to filter the array in such a way that it should remove extra spaces and only a single comma (without text).
Expected Output:
let array = ['john,1','mars,2','marry,3']
I tried a few methods which removed all the commas.
Please check jsfiddle
Down votes done by those who knows nothing.. :):):)
CodePudding user response:
array = array.filter(el => {return el.trim() !== ','})
CodePudding user response:
['john,1','mars,2','marry,3'].map(x=>x.replace(',',''))
result: ['john1', 'mars2', 'marry3']