how to split a string by spaces in javascript code example Example: js split text on spaces var string = "text to split"; var words = string.split(" ");