Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                const MenuList = [
  {
    "id": 1,
    "name": "系統設定",
    "sortNo": 1,
    "menuSubs": [
      {
        "id": 2,
        "name": "選單管理",
        "sortNo": 7,
        "url": "AdminControl/ug_Edit_Menu.aspx?IT=M__"
      },
      {
        "id": 5,
        "name": "銀行管理",
        "sortNo": 1,
        "url": "AdminControl/ug_Edit_Bank.aspx"
      },
      {
        "id": 6,
        "name": "語系管理",
        "sortNo": 2,
        "url": "AdminControl/ug_Edit_Language.aspx"
      },
      {
        "id": 7,
        "name": "靜態參數管理",
        "sortNo": 4,
        "url": "AdminControl/ug_Edit_Variable.aspx"
      },
      {
        "id": 11,
        "name": "郵遞區號表",
        "sortNo": 3,
        "url": "AdminControl/ug_Zip_List.aspx"
      },
      {
        "id": 133,
        "name": "商店訂單狀態管理",
        "sortNo": 8,
        "url": "AdminControl/ug_Edit_OrderType.aspx?IT=O_1"
      },
      {
        "id": 134,
        "name": "刊物訂單狀態管理",
        "sortNo": 9,
        "url": "AdminControl/ug_Edit_OrderType.aspx?IT=O_2"
      },
      {
        "id": 182,
        "name": "商店金流交易設定",
        "sortNo": 10,
        "url": "AdminControl/ug_Edit_OrderBank.aspx?IT=O_1"
      },
      {
        "id": 191,
        "name": "浮動欄位內容調整",
        "sortNo": 11,
        "url": "AdminControl/ug_Edit_Data.aspx?IT=BATCH"
      },
      {
        "id": 207,
        "name": "欠費訂單狀態管理",
        "sortNo": 12,
        "url": "AdminControl/ug_Edit_OrderType.aspx?IT=O_3"
      },
      {
        "id": 210,
        "name": "欠費金流交易設定",
        "sortNo": 13,
        "url": "AdminControl/ug_Edit_OrderBank.aspx?IT=O_3"
      }
    ]
  },
  {
    "id": 57,
    "name": "廣告管理",
    "sortNo": 4,
    "menuSubs": [
      {
        "id": 53,
        "name": "首頁大廣告",
        "sortNo": 1,
        "url": "banner/banner-list?IT=BN00"
      },
      {
        "id": 54,
        "name": "首頁3則小廣告",
        "sortNo": 3,
        "url": "banner/banner-list?IT=BN01"
      },
      {
        "id": 59,
        "name": "內頁大廣告",
        "sortNo": 11,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN10"
      },
      {
        "id": 60,
        "name": "內頁小廣告",
        "sortNo": 13,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN11"
      },
      {
        "id": 65,
        "name": "刊物大廣告",
        "sortNo": 14,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN21"
      },
      {
        "id": 76,
        "name": "商店大廣告",
        "sortNo": 17,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN31"
      },
      {
        "id": 124,
        "name": "首頁5則小廣告-A",
        "sortNo": 4,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN02"
      },
      {
        "id": 170,
        "name": "首頁大廣告-手機板",
        "sortNo": 2,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN00S"
      },
      {
        "id": 171,
        "name": "內頁大廣告-手機板",
        "sortNo": 12,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN10S"
      },
      {
        "id": 172,
        "name": "刊物大廣告-手機板",
        "sortNo": 15,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN21S"
      },
      {
        "id": 173,
        "name": "達人愛分享大廣告-手機板",
        "sortNo": 20,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN41S"
      },
      {
        "id": 174,
        "name": "商店大廣告-手機板",
        "sortNo": 18,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN31S"
      },
      {
        "id": 175,
        "name": "達人愛分享大廣告",
        "sortNo": 19,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN41"
      },
      {
        "id": 176,
        "name": "側邊廣告",
        "sortNo": 9,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN03"
      },
      {
        "id": 187,
        "name": "首頁5則小廣告-B",
        "sortNo": 5,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN02B"
      },
      {
        "id": 188,
        "name": "首頁5則小廣告-C",
        "sortNo": 6,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN02C"
      },
      {
        "id": 189,
        "name": "首頁5則小廣告-D",
        "sortNo": 7,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN02D"
      },
      {
        "id": 190,
        "name": "首頁5則小廣告-E",
        "sortNo": 8,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN02E"
      },
      {
        "id": 242,
        "name": "閒置廣告",
        "sortNo": 10,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN71"
      },
      {
        "id": 277,
        "name": "新官網首頁大廣告",
        "sortNo": 21,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN80"
      },
      {
        "id": 278,
        "name": "新官網首頁大廣告-手機板",
        "sortNo": 22,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN80S"
      },
      {
        "id": 279,
        "name": "新官網首頁浮動廣告",
        "sortNo": 23,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN81"
      },
      {
        "id": 280,
        "name": "新官網首頁浮動廣告-手機板",
        "sortNo": 24,
        "url": "BannerData/ug_Banner_List.aspx?IT=BN81S"
      }
    ]
  }
]

const func1 = (id) => {
  let result = '';
  MenuList.forEach(parent => {
    parent.menuSubs.forEach(sub => {
      if (sub.id.toString() === id) {
        result = sub.name;
      }
    });
  });
  return result;
}

const func2 = (id) => {
  for (let i = 0; i < MenuList.length; i += 1) {
    const menuSubs = MenuList[i].menuSubs;
    for (let j = 0; j < menuSubs.length; j += 1) {
      if (menuSubs[j].id.toString() === id) {
        return menuSubs[j].name;
      }
    }
  }
}

const func3 = (id) => {
  return MenuList.filter(el => el.menuSubs.filter(sub => sub.id.toString() === id).length)
}

const func4 = (id) => {
  let parentMenu = MenuList.filter(item => item.menuSubs.filter(sub => sub.id == id).length > 0);
  return parentMenu[0].menuSubs.find(sub => sub.id == id).name;
}

//console.log(func1('5'))
//console.log(func2('5'))
//const func3Result = func3('5');
//console.log(func3Result.length ? func3Result[0].name : '');
console.log(func4('5'))

              
            
!
999px

Console