String.prototype.trimStart()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
trimStart()
メソッドは、元の文字列を変更せずに、文字列の先頭のホワイトスペースを削除した新しい文字列を返します。trimLeft()
はこのメソッドの別名です。
試してみましょう
const greeting = " Hello world! ";
console.log(greeting);
// Expected output: " Hello world! ";
console.log(greeting.trimStart());
// Expected output: "Hello world! ";
構文
js
trimStart()
trimLeft()
返値
別名
例
trimStart() の使用
次の例は str
の先頭から空白を取り除きますが、末尾からは取り除きません。
js
let str = " foo ";
console.log(str.length); // 8
str = str.trimStart();
console.log(str.length); // 5
console.log(str); // 'foo '
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-string.prototype.trimstart |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
trimStart |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Uses a non-standard name.
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.