我如何在 es6 中优化 .concat 方法

How i can optimize .concat method in es6

我如何使用 ES6 功能优化 .contact 方法。 我的线路运行良好,但正在学习 ES6 ,并且希望获得一些很好的示例来编写具有某些 es6 功能的代码。 (解构或其他很酷的方式) 感谢

因为我不喜欢而需要优化的行是:

const list_B = buttonsType.toolz.concat(buttonsType.layerz,buttonsType.categoryz,buttonsType.sheetz,buttonsType.actionz);//***line to optimize */

上下文是:

const buttonsType = {// slots Names for interactive buttons editor
            toolz:['iconParentMode', 'move', 'pivot', 'scaleicon', 'skewicon', 'rotateicon', 'drawLine', 'sunNigth', 'lockAll', 'playPause',],
            layerz:[ 'gb0', 'gb1', 'gb2', 'gb3', 'gb4', 'gb5', 'gb6',],
            categoryz:[ 'All', 'Characteres', 'Rocks', 'Trees', 'Buildings', 'Grass', 'FurnitureINT', 'FurnitureEXT', 'Cliffs', 'Objets', 'Divers copie',],
            sheetz:[ 'SpriteSheets', 'TileSheets', 'Spines', 'Sprites',],
            actionz:[ 'iconRenderable', 'icon_PinGrid', 'icon_grid', 'saveIcon',],
        };
    //////// ┌------------------------------------------------------------------------------┐
    //////// CREATE BUTTONS GRAFICS INTERACTIONS
    ////////└------------------------------------------------------------------------------┘
        // make and store buttons Data's
        (function(){
            // how i can optimise for es6 and write proper this concat ?
           const list_B = buttonsType.toolz.concat(buttonsType.layerz,buttonsType.categoryz,buttonsType.sheetz,buttonsType.actionz);//***line to optimize */

           for (let [i,len] = [0,list_B.length]; i < len; i++) {
               const name = list_B[i];
               const slot = $PME.gui.skeleton.findSlot(name);
           };
        })();

编辑:已解决

    (function(){
   const list_B = Object.entries(buttonsType);
   for (let [i,len] = [0,list_B.length]; i < len; i++) {
       const [type,list_name] = [list_B[i][0], list_B[i][1]];
       list_name.forEach(name => {
        buttonsSlots[name] = $PME.gui.skeleton.findSlot(name);
        buttonsSlots[name].type = type;
       });
   };
})();

我不知道是否可以谈论优化,但我会这样做:

const list_B = Object.keys(buttonsType)
  .reduce((acc, key) => {
    return acc.concat(buttonsType[key]);
  },[]); 

遍历 buttonsType 中的键。 Concat 到 reduce every array inside buttonsType's keys

的空数组

你可以使用 Object.entries

let a = [];
Object.entries(buttonsType).forEach(item => {a = a.concat(item[1])});