{"id":3342,"date":"2024-11-10T13:31:24","date_gmt":"2024-11-10T05:31:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3342\/"},"modified":"2024-11-10T13:31:24","modified_gmt":"2024-11-10T05:31:24","slug":"js%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e5%a4%9a%e4%b8%aa%e7%a9%ba%e6%a0%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3342\/","title":{"rendered":"js\u5982\u4f55\u4f7f\u7528\u591a\u4e2a\u7a7a\u683c"},"content":{"rendered":"<blockquote><p>\n  \u5728 javascript \u4e2d\u4f7f\u7528\u591a\u4e2a\u7a7a\u683c\u7684\u65b9\u6cd5\u6709\uff1a\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u8fde\u63a5\u8fd0\u7b97\u7b26repeat() \u65b9\u6cd5string.prototype.padend() \u65b9\u6cd5\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110810063531871.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u4f7f\u7528\u591a\u4e2a\u7a7a\u683c\u63d2\u56fe\" alt=\"js\u5982\u4f55\u4f7f\u7528\u591a\u4e2a\u7a7a\u683c\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528\u591a\u4e2a\u7a7a\u683c<\/strong><\/p>\n<p>\u5728 JavaScript \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u4f7f\u7528\u591a\u4e2a\u7a7a\u683c\uff1a<\/p>\n<p><strong>1. \u5b57\u7b26\u4e32\u5b57\u9762\u91cf<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u6765\u521b\u5efa\u5305\u542b\u591a\u4e2a\u7a7a\u683c\u7684\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre>const str = \"Hello   World\";\nconsole.log(str);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>Hello   World<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>2. \u8fde\u63a5\u8fd0\u7b97\u7b26<\/strong><\/p>\n<p>\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u6216\u53d8\u91cf\u4f7f\u7528\u52a0\u53f7\uff08+\uff09\u8fde\u63a5\u8fd0\u7b97\u7b26\u8fde\u63a5\u8d77\u6765\uff1a<\/p>\n<pre>const str1 = \"Hello\";\nconst str2 = \"  World\";\nconst str3 = str1 + str2;\nconsole.log(str3);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>Hello  World<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>3. repeat() \u65b9\u6cd5<\/strong><\/p>\n<p>\u8fd8\u53ef\u4ee5\u4f7f\u7528 repeat() \u65b9\u6cd5\u6765\u91cd\u590d\u4e00\u4e2a\u5b57\u7b26\u4e32\u6307\u5b9a\u6b21\u6570\uff1a<\/p>\n<pre>const str = \" \".repeat(3);\nconsole.log(str);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<p><strong>4. String.prototype.padEnd() \u65b9\u6cd5<\/strong><\/p>\n<p>padEnd() \u65b9\u6cd5\u53ef\u4ee5\u5728\u5b57\u7b26\u4e32\u672b\u5c3e\u586b\u5145\u6307\u5b9a\u5b57\u7b26\uff0c\u5305\u62ec\u7a7a\u683c\uff1a<\/p>\n<pre>const str = \"Hello\".padEnd(10, \" \");\nconsole.log(str);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>Hello     <\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u4f7f\u7528\u591a\u4e2a\u7a7a\u683c\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 javascript \u4e2d\u4f7f\u7528\u591a\u4e2a\u7a7a\u683c\u7684\u65b9\u6cd5\u6709\uff1a\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u8fde\u63a5\u8fd0\u7b97\u7b26repeat() \u65b9\u6cd5string.prototype.padend() \u65b9\u6cd5 \u5982\u4f55\u4f7f\u7528\u591a\u4e2a\u7a7a\u683c \u5728 JavaScript \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u4f7f\u7528\u591a\u4e2a\u7a7a\u683c\uff1a 1. \u5b57\u7b26\u4e32\u5b57\u9762\u91cf \u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u6765\u521b\u5efa\u5305\u542b\u591a\u4e2a\u7a7a\u683c\u7684\u5b57\u7b26\u4e32\uff1a const str = &#8220;Hello World&#8221;; console.log(str); \u767b\u5f55\u540e\u590d\u5236 \u8f93\u51fa\uff1a Hello World \u767b\u5f55\u540e\u590d\u5236 2. \u8fde\u63a5\u8fd0\u7b97\u7b26 \u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u6216\u53d8\u91cf\u4f7f\u7528\u52a0\u53f7\uff08+\uff09\u8fde\u63a5\u8fd0\u7b97\u7b26\u8fde\u63a5\u8d77\u6765\uff1a const str1 = &#8220;Hello&#8221;; const str2 = &#8221; World&#8221;; const str3 = str1 + str2; console.log(str3); \u767b\u5f55\u540e\u590d\u5236 \u8f93\u51fa\uff1a Hello World \u767b\u5f55\u540e\u590d\u5236 3. repeat() \u65b9\u6cd5 \u8fd8\u53ef\u4ee5\u4f7f\u7528 repeat() \u65b9\u6cd5\u6765\u91cd\u590d\u4e00\u4e2a\u5b57\u7b26\u4e32\u6307\u5b9a\u6b21\u6570\uff1a const str [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3342","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3342"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3342\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}