pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/trim

cript src="/static/client/4585.458a2b03d77c78d5.js" type="module">

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

String.prototype.trim()

Baseline 広く利用可能

この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2015年7月以降、すべてのブラウザーで利用可能です。

trim()String 値のメソッドで、この文字列の両端からホワイトスペースを取り除き、元の文字列を変更せずに新しい文字列を返します。

一方の端からのみホワイトスペースを取り除いた新しい文字列を返したい場合は、trimStart() または trimEnd() を使用してください。

試してみましょう

const greeting = "   Hello world!   ";

console.log(greeting);
// 予想される結果: "   Hello world!   ";

console.log(greeting.trim());
// 予想される結果: "Hello world!";

構文

js
trim()

引数

なし。

返値

str の先頭と末尾のホワイトスペースを取り除いた新しい文字列を表します。 ホワイトスペースはホワイトスペース文字と改行文字で定義します。

str の先頭にも末尾にもホワイトスペースがなかった場合でも、新しい文字列が返されます(基本的には str のコピー)。

trim() の使用

次の例は、str の両端からホワイトペースを取り除きます。

js
const str = "   foo  ";
console.log(str.trim()); // 'foo'

仕様書

仕様書
ECMAScript® 2027 Language Specification
# sec-string.prototype.trim

ブラウザーの互換性

関連情報

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy