• <bdo id='MImO0'></bdo><ul id='MImO0'></ul>

    <small id='MImO0'></small><noframes id='MImO0'>

  1. <legend id='MImO0'><style id='MImO0'><dir id='MImO0'><q id='MImO0'></q></dir></style></legend><tfoot id='MImO0'></tfoot>

      <i id='MImO0'><tr id='MImO0'><dt id='MImO0'><q id='MImO0'><span id='MImO0'><b id='MImO0'><form id='MImO0'><ins id='MImO0'></ins><ul id='MImO0'></ul><sub id='MImO0'></sub></form><legend id='MImO0'></legend><bdo id='MImO0'><pre id='MImO0'><center id='MImO0'></center></pre></bdo></b><th id='MImO0'></th></span></q></dt></tr></i><div id='MImO0'><tfoot id='MImO0'></tfoot><dl id='MImO0'><fieldset id='MImO0'></fieldset></dl></div>

      如何将值数组添加到 Set

      How to add an array of values to a Set(如何将值数组添加到 Set)

          <legend id='V760w'><style id='V760w'><dir id='V760w'><q id='V760w'></q></dir></style></legend>
            <bdo id='V760w'></bdo><ul id='V760w'></ul>

            <small id='V760w'></small><noframes id='V760w'>

              • <tfoot id='V760w'></tfoot>
                <i id='V760w'><tr id='V760w'><dt id='V760w'><q id='V760w'><span id='V760w'><b id='V760w'><form id='V760w'><ins id='V760w'></ins><ul id='V760w'></ul><sub id='V760w'></sub></form><legend id='V760w'></legend><bdo id='V760w'><pre id='V760w'><center id='V760w'></center></pre></bdo></b><th id='V760w'></th></span></q></dt></tr></i><div id='V760w'><tfoot id='V760w'></tfoot><dl id='V760w'><fieldset id='V760w'></fieldset></dl></div>
                  <tbody id='V760w'></tbody>
              • 本文介绍了如何将值数组添加到 Set的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                将数组的所有值添加到 Set 的老式方法是:

                The old school way of adding all values of an array into the Set is:

                // for the sake of this example imagine this set was created somewhere else 
                // and I cannot construct a new one out of an array
                let mySet = new Set()
                
                for(let item of array) {
                  mySet.add(item)
                }
                

                有没有更优雅的方式来做到这一点?也许是 mySet.add(array)mySet.add(...array)?

                Is there a more elegant way of doing this? Maybe mySet.add(array) or mySet.add(...array)?

                PS:我知道两者都不起作用

                PS: I know both do not work

                推荐答案

                虽然 Set API 仍然非常简约,但您可以使用 Array.prototype.forEach 并稍微缩短您的代码:

                While Set API is still very minimalistic, you can use Array.prototype.forEach and shorten your code a bit:

                array.forEach(item => mySet.add(item))
                
                // alternative, without anonymous arrow function
                array.forEach(mySet.add, mySet)
                

                这篇关于如何将值数组添加到 Set的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                quot;Status Code:200 OK (from ServiceWorker)quot; in Chrome Network DevTools?(“状态码:200 OK(来自 ServiceWorker)在 Chrome 网络开发工具中?)
                How to set a header for a HTTP GET request, and trigger file download?(如何为 HTTP GET 请求设置标头并触发文件下载?)
                Adding custom HTTP headers using JavaScript(使用 JavaScript 添加自定义 HTTP 标头)
                SQL Query DocumentDB in Azure Functions by an integer not working(通过整数在 Azure Functions 中 SQL 查询 DocumentDB 不起作用)
                Azure Functions [JavaScript / Node.js] - HTTP call, good practices(Azure Functions [JavaScript/Node.js] - HTTP 调用,良好实践)
                Azure Functions - Import Custom Node Module(Azure Functions - 导入自定义节点模块)

                  1. <tfoot id='4LtY6'></tfoot>
                        <tbody id='4LtY6'></tbody>

                      <small id='4LtY6'></small><noframes id='4LtY6'>

                        <bdo id='4LtY6'></bdo><ul id='4LtY6'></ul>
                      • <legend id='4LtY6'><style id='4LtY6'><dir id='4LtY6'><q id='4LtY6'></q></dir></style></legend>

                          <i id='4LtY6'><tr id='4LtY6'><dt id='4LtY6'><q id='4LtY6'><span id='4LtY6'><b id='4LtY6'><form id='4LtY6'><ins id='4LtY6'></ins><ul id='4LtY6'></ul><sub id='4LtY6'></sub></form><legend id='4LtY6'></legend><bdo id='4LtY6'><pre id='4LtY6'><center id='4LtY6'></center></pre></bdo></b><th id='4LtY6'></th></span></q></dt></tr></i><div id='4LtY6'><tfoot id='4LtY6'></tfoot><dl id='4LtY6'><fieldset id='4LtY6'></fieldset></dl></div>