Skip to main content Accessibility Feedback

Strings

String.trim()

Remove leading and trailing whitespace from a string.

var str = '   I love Cape Cod potato chips.   ';

// Returns "I love Cape Cod potato chips."
str.trim();

Works in all modern browsers, and IE9+. You can extend support back further with polyfills.