{"id":1906,"date":"2023-03-25T14:26:38","date_gmt":"2023-03-25T06:26:38","guid":{"rendered":""},"modified":"2023-03-25T14:26:38","modified_gmt":"2023-03-25T06:26:38","slug":"ES6 \u6269\u5c55\u8fd0\u7b97\u7b26","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1906.html","title":{"rendered":"ES6 \u6269\u5c55\u8fd0\u7b97\u7b26"},"content":{"rendered":"
\n
var <\/span>variablename1 = [...value];<\/pre>\n<\/code>\n <\/div>\n
\n \u4ee5\u4e0a\u8bed\u6cd5\u4e2d\u7684\u4e09\u4e2a\u70b9(...) \u662f\u6269\u5c55\u8fd0\u7b97\u7b26\uff0c\u5b83\u9488\u5bf9\u7279\u5b9a\u53d8\u91cf\u4e2d\u7684\u6574\u4e2a\u503c\u3002\n <\/div>\n\n \u8ba9\u6211\u4eec\u5c1d\u8bd5\u4e86\u89e3\u6269\u5c55\u8fd0\u7b97\u7b26\u5728\u4e0d\u540c\u6848\u4f8b:\n <\/div>\n\u6269\u5c55\u8fd0\u7b97\u7b26\u548c\u6570\u7ec4\u64cd\u4f5c<\/h2>\n\n \u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u770b\u5230\u5982\u4f55\u4f7f\u7528\u6269\u5c55\u8fd0\u7b97\u7b26\u6765\u64cd\u4f5c\u6570\u7ec4\u3002\n <\/div>\n\u6784\u9020\u6570\u7ec4\u5b57\u9762\u91cf<\/h3>\n\n \u5f53\u6211\u4eec\u4f7f\u7528\u5b57\u9762\u91cf\u5f62\u5f0f\u6784\u9020\u6570\u7ec4\u65f6\uff0c\u5c55\u5f00\u8fd0\u7b97\u7b26\u5141\u8bb8\u6211\u4eec\u5728\u5df2\u521d\u59cb\u5316\u7684\u6570\u7ec4\u4e2d\u63d2\u5165\u53e6\u4e00\u4e2a\u6570\u7ec4\u3002\n <\/div>\n\n \u793a\u4f8b\n <\/div>\n\nlet colors = ['Red'<\/span>, 'Yellow'<\/span>];\nlet newColors = [...colors, 'Violet'<\/span>, 'Orange'<\/span>, 'Green'<\/span>];\nconsole.log<\/span>(newColors);<\/pre>\n<\/code>\n <\/div>\n
\n \u8f93\u51fa\n <\/div>\n\n[ 'Red'<\/span>, 'Yellow'<\/span>, 'Violet'<\/span>, 'Orange'<\/span>, 'Green'<\/span> ]<\/pre>\n<\/code>\n <\/div>\n
\u8fde\u63a5\u6570\u7ec4<\/h3>\n\n \u6269\u5c55\u8fd0\u7b97\u7b26\u4e5f\u53ef\u7528\u4e8e\u8fde\u63a5\u4e24\u4e2a\u6216\u591a\u4e2a\u6570\u7ec4\u3002\n <\/div>\n\n \u793a\u4f8b\n <\/div>\n\nlet colors = ['Red'<\/span>, 'Yellow'<\/span>];\nlet newColors = [...colors, 'Violet'<\/span>, 'Orange'<\/span>, 'Green'<\/span>];\nconsole.log<\/span>(newColors);<\/pre>\n<\/code>\n <\/div>\n
\n \u8f93\u51fa\n <\/div>\n\n[ 'Red'<\/span>, 'Yellow'<\/span>, 'Violet'<\/span>, 'Orange'<\/span>, 'Green'<\/span> ]<\/pre>\n<\/code>\n <\/div>\n
\u590d\u5236\u6570\u7ec4<\/h3>\n\n \u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5c55\u5f00\u8fd0\u7b97\u7b26\u590d\u5236\u6570\u7ec4\u7684\u5b9e\u4f8b\u3002\n <\/div>\n\n \u793a\u4f8b\n <\/div>\n\nlet colors = ['Red'<\/span>, 'Yellow'<\/span>];\nlet newColors = [...colors];\nconsole.log<\/span>(newColors);<\/pre>\n<\/code>\n <\/div>\n
\n \u8f93\u51fa\n <\/div>\n\n[ 'Red'<\/span>, 'Yellow'<\/span> ]<\/pre>\n<\/code>\n <\/div>\n
\n \u5982\u679c\u6211\u4eec\u4e0d\u4f7f\u7528\u6269\u5c55\u8fd0\u7b97\u7b26\u590d\u5236\u6570\u7ec4\u5143\u7d20\uff0c\u90a3\u4e48\u5728\u590d\u5236\u7684\u6570\u7ec4\u4e2d\u63d2\u5165\u65b0\u5143\u7d20\u4f1a\u5f71\u54cd\u539f\u59cb\u6570\u7ec4\u3002\n <\/div>\n\n \u4f46\u5982\u679c\u6211\u4eec\u4f7f\u7528\u6269\u5c55\u8fd0\u7b97\u7b26\u590d\u5236\u6570\u7ec4\uff0c\u90a3\u4e48\u5728\u590d\u5236\u7684\u6570\u7ec4\u4e2d\u63d2\u5165\u4e00\u4e2a\u5143\u7d20\u4e0d\u4f1a\u5f71\u54cd\u5230\u539f\u6765\u7684\u6570\u7ec4\u3002\n <\/div>\n\n \u6211\u4eec\u6765\u7406\u89e3\u4e00\u4e0b\u8fd9\u4e2a\u4f8b\u5b50\u3002\n <\/div>\n\n \u4f8b\u5b50\n <\/div>\n\n \u4e0d\u4f7f\u7528\u6269\u5c55\u8fd0\u7b97\u7b26\n <\/div>\n\nlet colors = ['Red'<\/span>, 'Yellow'<\/span>];\nlet newColors = colors;\nnewColors.push<\/span>('Green'<\/span>);\nconsole.log<\/span>(newColors);\nconsole.log<\/span>(colors);<\/pre>\n<\/code>\n <\/div>\n
\n \u8f93\u51fa\n <\/div>\n\n[ 'Red'<\/span><\/span>, 'Yellow'<\/span><\/span>, 'Green'<\/span><\/span> ]\n[ 'Red', 'Yellow', 'Green' ]<\/pre>\n<\/code>\n <\/div>\n
\n \u4f7f\u7528\u6269\u5c55\u8fd0\u7b97\u7b26\n <\/div>\n\nlet colors = ['Red'<\/span>, 'Yellow'<\/span>];\nlet newColors = [...colors];\nnewColors.push<\/span>('Green'<\/span>);\nconsole.log<\/span>(newColors);\nconsole.log<\/span>(colors);<\/pre>\n<\/code>\n <\/div>\n
\n \u8f93\u51fa\n <\/div>\n\n[ 'Red'<\/span><\/span>, 'Yellow'<\/span><\/span>, 'Green'<\/span> ]\n[ 'Red', 'Yellow' ]<\/pre>\n<\/code>\n <\/div>\n
\n \u6ce8\u610f: <\/span>\u5c55\u5f00\u8fd0\u7b97\u7b26\u53ea\u5c06\u6570\u7ec4\u672c\u8eab\u590d\u5236\u5230\u65b0\u6570\u7ec4\uff0c\u800c\u4e0d\u662f\u5143\u7d20\u3002\u8fd9\u610f\u5473\u7740\u64cd\u4f5c\u5458\u53ef\u4ee5\u505a\u6d45\u62f7\u8d1d\u800c\u4e0d\u662f\u6df1\u62f7\u8d1d\u3002\n <\/div>\n\u5c55\u5f00\u8fd0\u7b97\u7b26\u548c\u5b57\u7b26\u4e32<\/h2>\n\n \u8ba9\u6211\u4eec\u770b\u770b\u5c55\u5f00\u8fd0\u7b97\u7b26\u5982\u4f55\u5c55\u5f00\u5b57\u7b26\u4e32\u3002\u4e0b\u9762\u7ed9\u51fa\u4e86\u76f8\u540c\u7684\u8bf4\u660e\u3002\n <\/div>\n\n \u793a\u4f8b\n <\/div>\n\n \u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u4ece\u5355\u4e2a\u5b57\u7b26\u4e32\u6784\u9020\u4e86\u4e00\u4e2a\u6570\u7ec4 str\u3002\n <\/div>\n\nlet str = ['A'<\/span>, ...'EIO'<\/span>, 'U'<\/span>];\nconsole.log<\/span>(str);<\/pre>\n<\/code>\n <\/div>\n
\n \u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u6269\u5c55\u8fd0\u7b97\u7b26\u5e94\u7528\u4e8e\u5b57\u7b26\u4e32'EIO'\u3002\u5b83\u5c06'EIO'\u5b57\u7b26\u4e32\u7684\u6bcf\u4e2a\u7279\u5b9a\u5b57\u7b26\u5c55\u5f00\u6210\u5355\u4e2a\u5b57\u7b26\u3002\n <\/div>\n\n \u6267\u884c\u4e0a\u8ff0\u4ee3\u7801\u540e\uff0c\u6211\u4eec\u5c06\u5f97\u5230\u4ee5\u4e0b\u8f93\u51fa\u3002\n <\/div>\n\n \u8f93\u51fa\n <\/div>\n\n[ 'A'<\/span>, 'E'<\/span>, 'I'<\/span>, 'O'<\/span>, 'U'<\/span> ]<\/pre>\n<\/code>\n <\/div>\n
<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"ES6 \u6269\u5c55\u8fd0\u7b97\u7b26zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[161],"tags":[],"class_list":["post-1906","post","type-post","status-publish","format-standard","hentry","category-es6jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1906"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=1906"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1906\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=1906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=1906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=1906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}