Javascript trim whitespace

Javascript trim whitespace function is used to remove whitespace from the string . include starting point and ending point of string

Syntax

trim()

trimLeft()

trimRight()

string.trim()  function remove whitespace from both starting and ending point of string

Example

Parameter Details

ParameterDescription
noit doesn't take any parameter

Technical Details

Return value
str.trim() function return original string without whitespace

Browser Support

Browser
Version4
3.5
10.5
10
5

trimLeft / trimStart

trimLeft or trimStart function used to remove whitespace from starting point of string

Example

trimRight / trimEnd

trimRight or trimEnd used  to remove whitespace from ending point of string

Example

Tips - trimStart is alias of  trimLeft

Tips - trimEnd is alias of trimRight

Note - trim function doesn't throw error if no whitespace are available in string i.e starting or ending point of string doesn't have whitespace