Home > other >  Remove single comma from an array in jQuery
Remove single comma from an array in jQuery

Time:06-25

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

  • Related