Dilip G Dilip G - 17 days ago 11
Node.js Question

how to remove all the occurence of . from array

i want to remove all the occurences of

.
from my
array


var arr = ['...my name is apple', 'my girl .... friend is banana.......'];


here is a code i'm using



var arr = ['...my name is apple', 'my girl .... friend is banana.......'];

var toRemove = '/\.+/g';
arr = arr.map(function(el) {
return el.replace(toRemove, ' ');
});

console.log(arr);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>





why the above code is not removing every occurences of
.
i don't know?

please help me thanks in advance

Answer

You don't need quotes for regex. Try this:

var arr = ['...my name is apple', 'my girl .... friend is banana.......'];

var toRemove = /\.+/g;  
arr = arr.map(function(el) {
  return el.replace(toRemove, ' ');
});

console.log(arr);