English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript String trim() Method

 JavaScript String Object

trim()The method removes the spaces at the beginning and end of the string.

Syntax:

string.trim()
var greeting = "         Hello world!         ";
greeting.trim();
Test and See‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the trim() method:

Method
trim()Yes3.510.559

Technical Details

Return Value:A new string representing the call string with spaces removed from both ends
JavaScript Version:ECMAScript 1

 JavaScript String Object