JavaScriptStringtrim

Removes whitespace from both ends of a string.

Syntax

str.trim()

Example

Enter values below to update the example in real time.

const
console
const text = "  hello world  ";
console.log(text.trim());   // "hello world"