Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
trim() は String 値のメソッドで、この文字列の両端からホワイトスペースを取り除き、元の文字列を変更せずに新しい文字列を返します。
一方の端からのみホワイトスペースを取り除いた新しい文字列を返したい場合は、trimStart() または trimEnd() を使用してください。
なし。
str の先頭と末尾のホワイトスペースを取り除いた新しい文字列を表します。 ホワイトスペースはホワイトスペース文字と改行文字で定義します。
str の先頭にも末尾にもホワイトスペースがなかった場合でも、新しい文字列が返されます(基本的には str のコピー)。
次の例は、str の両端からホワイトペースを取り除きます。
| ECMAScript® 2027 Language Specification # sec-string.prototype.trim |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年8月22日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.