I want to extract all the words from a string and out them in an array.
By "word" I mean a series of consecutive letters. If I have a space or other characters, the word ends there.
For example, if I have this string:
"my name is sil/ves tru, what?is."
I want an array like this:
arr[0] = "my";
arr[1] = "name";
arr[2] = "is";
arr[3] = "sil";
arr[4] = "ves";
arr[5] = "tru";
arr[6] = "what";
arr[7] = "is";
This is what I currently have:
var str = "my name is sil/ves tru, what?is."; //my string
var i;
var arr = [];
for (i = 0; i < str.length; i++) { //check all positions
if ((str[i] >= "a") && (str[i] <= "z")) { //check where string don't have letter and put the word in arr
//help me here
}
}
console.log(arr); //my array with words