• <bdo id='8vcIy'></bdo><ul id='8vcIy'></ul>
    1. <legend id='8vcIy'><style id='8vcIy'><dir id='8vcIy'><q id='8vcIy'></q></dir></style></legend>

      <tfoot id='8vcIy'></tfoot>
    2. <small id='8vcIy'></small><noframes id='8vcIy'>

        <i id='8vcIy'><tr id='8vcIy'><dt id='8vcIy'><q id='8vcIy'><span id='8vcIy'><b id='8vcIy'><form id='8vcIy'><ins id='8vcIy'></ins><ul id='8vcIy'></ul><sub id='8vcIy'></sub></form><legend id='8vcIy'></legend><bdo id='8vcIy'><pre id='8vcIy'><center id='8vcIy'></center></pre></bdo></b><th id='8vcIy'></th></span></q></dt></tr></i><div id='8vcIy'><tfoot id='8vcIy'></tfoot><dl id='8vcIy'><fieldset id='8vcIy'></fieldset></dl></div>
      1. 如何使用 javascript 更改一个对象中的键?

        How to change the keys in one object with javascript?(如何使用 javascript 更改一个对象中的键?)
      2. <tfoot id='gWCrQ'></tfoot>

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

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

                  <tbody id='gWCrQ'></tbody>
                <legend id='gWCrQ'><style id='gWCrQ'><dir id='gWCrQ'><q id='gWCrQ'></q></dir></style></legend>
                1. 本文介绍了如何使用 javascript 更改一个对象中的键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有:

                      var myAbc = { 0: true, 1: false, 2: true };
                  

                  我想更改 de 键,例如:

                  and i want to change de keys like:

                  var myAbc = { key1: true, key2: false, key3: true };
                  

                  我已经试过了:

                   for (var key in array) {
                              key = value;
                          }
                  

                  但是没有改变数组的键位在for的外面,有什么帮助吗?

                  but did not change the key of the array out side of the for, any help?

                  推荐答案

                  如果你会用es6,你可以一行行搞定:

                  If you can use es6, you can do this in one line:

                  var myAbc = { 0: true, 1: false, 2: true };
                  
                  var renamed = Object.keys(myAbc).reduce((p, c) => { p[`key${Number(c)+1}`] = myAbc[c]; return p; }, {})
                  
                  console.log(renamed)

                  这篇关于如何使用 javascript 更改一个对象中的键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                    <legend id='ONJ6e'><style id='ONJ6e'><dir id='ONJ6e'><q id='ONJ6e'></q></dir></style></legend>
                          <bdo id='ONJ6e'></bdo><ul id='ONJ6e'></ul>

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

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

                          <tfoot id='ONJ6e'></tfoot>
                              <tbody id='ONJ6e'></tbody>