

Note that the index of the first letter of the string is 0, and that spaces are counted. > "born one mornin’ when the sun didn’t shine" Var birth = "I was born one mornin’ when the sun didn’t shine" It does so using a numerical index, with an optional termination point. Var lyrics = "You load sixteen tons what do you get" The opposite of split() is, not surprisingly, join().Īn optional integer after the split character or regular expression will limit the size of the resulting array: This can be particularly useful when the character is already known, such as the slashes in a file path: Splitīreaks a string into an array based on a particular character, or regular expression. As a result, there are many different methods for dealing with strings, but slice and split are some of the most useful. Strings can be chopped and diced in many different ways in JavaScript, and for many different purposes.
