Adding content to the DOM often involves a series of concatenations to bring information into a static string, such as this example:

Adding content to the DOM often involves a series of concatenations to bring information into a static string, such as this example:
User-submitted text entered into forms is often padded with spaces, usually generated by accidentally hitting the space bar inside a text input. Site owners almost always want to erase this extra data: it would be confusing for a user to have their login attempt rejected just because their original signup included an unseen space.
Strings can be chopped and diced in many different ways in JavaScript, and for many different purposes. As a result, there are many different methods for dealing with strings, but slice
and split
are some of the most useful.