I am looking to take a string and find all the spaces in it and separate that into different variables. I know I could use the .split()
but that wouldn\'t make
If you don't know how many spaces there are in the string, beforehand, you can do the following:
var str = "How are you doing today, my dear friend?";
numberspaces = str.split(" ").length; //you know how many spaces there are
words=str.split(" "); //it creates an array of words
var i;
for (i = 0; i < numberspaces; i++){
console.log(words[i]);}