String

String.prototype.trimStart

Removes whitespace from the beginning of a string and returns a new string

Syntax

JavaScript
string.trimStart()

Return Value

A new string with leading whitespace removed

Examples

Basic Usage
const str = '   Hello   ';
console.log(str.trimStart()); // 'Hello   '
Practical Example
const indented = '    code line';
console.log(indented.trimStart()); // 'code line'
Advanced Usage
console.log('  \t\n  test'.trimStart()); // 'test'

Understanding String.prototype.trimStart

The String.prototype.trimStart method in JavaScript removes whitespace from the beginning of a string and returns a new string. It belongs to the String object and is one of the most widely used methods for working with string values in modern JavaScript and TypeScript applications.

The method signature is string.trimStart(). When called, it returns a new string with leading whitespace removed. Understanding when and how to use trimStart() helps you write more expressive, readable code.

Common use cases for String.prototype.trimStart include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like string-trimend, string-trim, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for String.prototype.trimStart is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More String Methods

Other methods in the String object

Related Tools

More String Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.