views:

934

answers:

3

Hello. I have an array in javascript. This array has strings that contains commas (","). I want all commas to be removed from this array. Can this be done ?

Thanks.

+1  A: 

Sure -- just iterate through the array and do a standard removal on each iteration.

Or if the nature of your array permits, you could first convert the array to a string, take out the commas, then convert back into an array.

fig
A: 

Given the required string in variable s :-

var result = s.replace(/,/g, '');
AnthonyWJones
+7  A: 

Yes.

for(var i=0; i < arr.length; i++) {
 arr[i] = arr[i].replace(/,/g, '');
}
Kekoa
+1 for getting closer than me but you need to do something with the result, replace does not mutate the string.
AnthonyWJones
Sorry kekoav, Shoudn't it be:arr[i] = arr[i].replace(/,/g, '');??
tekBlues
@tekBlues - yes, updated code
Kekoa