diff options
author | Florian Merz <me@fiji-flo.de> | 2021-02-11 12:56:40 +0100 |
---|---|---|
committer | Florian Merz <me@fiji-flo.de> | 2021-02-11 12:56:40 +0100 |
commit | 310fd066e91f454b990372ffa30e803cc8120975 (patch) | |
tree | d5d900deb656a5da18e0b60d00f0db73f3a2e88e /files/zh-cn/web/javascript/reference/global_objects/string/trimend | |
parent | 8260a606c143e6b55a467edf017a56bdcd6cba7e (diff) | |
download | translated-content-310fd066e91f454b990372ffa30e803cc8120975.tar.gz translated-content-310fd066e91f454b990372ffa30e803cc8120975.tar.bz2 translated-content-310fd066e91f454b990372ffa30e803cc8120975.zip |
unslug zh-cn: move
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/string/trimend')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/string/trimend/index.html | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/trimend/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/trimend/index.html new file mode 100644 index 0000000000..9c8319cb29 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/string/trimend/index.html @@ -0,0 +1,84 @@ +--- +title: String.prototype.trimRight() +slug: Web/JavaScript/Reference/Global_Objects/String/TrimRight +tags: + - JavaScript + - Method + - Prototype + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/trimEnd +--- +<div>{{JSRef}}</div> + +<p><code><strong>trimEnd()</strong> </code>方法从一个字符串的末端移除空白字符。trimRight() 是这个方法的别名。</p> + +<p>{{EmbedInteractiveExample("pages/js/string-trimend.html")}}</p> + +<p>The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="syntaxbox"><code><var>str</var>.trimEnd(); +<var>str</var>.trimRight();</code></pre> + +<h3 id="返回值">返回值</h3> + +<p>一个新字符串,表示从调用字串的末(右)端除去空白。</p> + +<h2 id="Description" name="Description">描述</h2> + +<p><code>trimEnd()</code> / <code>trimRight()</code>方法移除原字符串右端的连续空白符并返回,<code>trimEnd()</code> / <code>trimRight()</code>方法并不会直接修改原字符串本身。</p> + +<h3 id="别名">别名</h3> + +<p>为了与 {{jsxref("String.prototype.padEnd")}} 等函数保持一致,标准方法名称为<code>trimEnd</code>。 但是,出于Web兼容性原因,<code>trimRight</code>仍然是<code>trimEnd</code>的别名。 在某些引擎中,这意味着:</p> + +<pre class="brush: js"><code>String.prototype.trimRight.name === "trimEnd";</code> +</pre> + +<h2 id="Examples" name="Examples">示例</h2> + +<h3 id="使用trimEnd">使用<code>trimEnd()</code></h3> + +<p>下面的例子输出了小写的字符串" foo":</p> + +<pre class="brush:js;highlight:[5]">var str = " foo "; + +alert(str.length); // 8 + +str = str.trimRight(); // 或写成str = str.trimEnd(); +console.log(str.length); // 6 +console.log(str); // ' foo' +</pre> + +<h2 id="Specifications">Specifications</h2> + +<table> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td><code><a href="https://github.com/tc39/proposal-string-left-right-trim/#stringprototypetrimstart--stringprototypetrimend">String.prototype.{trimStart,trimEnd}</a></code>proposal</td> + <td>Stage 4</td> + <td>Expected to be part of ES2019</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<p>The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> + +<p>{{Compat("javascript.builtins.String.trimEnd")}}</p> + +<h2 id="See_also" name="See_also">相关链接</h2> + +<ul> + <li>{{jsxref("String.prototype.trim()")}}</li> + <li>{{jsxref("String.prototype.trimStart()")}}</li> +</ul> |