I have a simple code right here that is supposed to take the periods out of a string and then split all the words into an array. The array part works fine, but using .replace
on my string only removes the first period. Isn't it supposed to remove all instances of a period? The result I get in the console is:
["This", "is", "a", "test", "of", "the", "emergency", "broadcast", "system", "This", "is", "only", "a", "test."]
As you can see the last period is still there. Why is it not being removed by my string replace and how can I take all the periods out of the string?
Here is my code:
var the_string = "This is a test of the emergency broadcast system. This is only a test.";
var str_words = the_string.replace(".", "");
str_words = str_words.split(" ");
console.log(str_words);