JavaScript Glossary: String trim()

Publikováno: 25.3.2019

Basics

This method removes whitespaces from the start and end of the calling string. It removes spaces, tabs, no break spaces etc. It returns a new string stripped of whitespaces from both...

Celý článek

Basics

This method removes whitespaces from the start and end of the calling string. It removes spaces, tabs, no break spaces etc. It returns a new string stripped of whitespaces from both sides of the array.

"   hello world   ".trim()
// hello world

https://scotch.io/embed/gist/bbba1b8376fb9ccaf2f8ea21114a2537

Note the method is also case sensitive

Syntax

const trimmedSent = oldString.trim()

Returns a String

A new string object without whitespace at both ends. It doesn’t change the calling string.

Common Uses and Snippets

Removing whitespace from both ends of a string

This involves trimming user input strings before sending to the server:

https://scotch.io/embed/gist/5ef321045fd2dee5692f8455688a6a20

Nahoru
Tento web používá k poskytování služeb a analýze návštěvnosti soubory cookie. Používáním tohoto webu s tímto souhlasíte. Další informace