• <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 更改一个对象中的键?

        时间:2023-09-05
      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 更改一个对象中的键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:适用于ajax嵌入式图像链接的jquery图像预览? 下一篇:在页面刷新后更改默认 iframe src onclick 并保留 src?

                  相关文章

                  <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'>

                    1. <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>

                    2. <tfoot id='ONJ6e'></tfoot>