how to split string along spaces and create array in js code example Example: js split text on spaces var string = "text to split"; var words = string.split(" ");