Use enumeration in js

One: The following is the solution that I thought of first when I made a judgment before

      if (level == 1001) {
        return "城市合伙人发起人";
      } else if (level == 1002) {
        return "准城市合伙人";
      } else if (level == 1003) {
        return "合格城市合伙人";
      } else if (level == 1004) {
        return "金牌城市合伙人";
      } else if (level == 1005) {
        return "钻石城市合伙人";
      }

Return different values ​​depending on the state value

Two: After doing some projects, I learned that I can also use enumeration to solve

      const levelObject= {
        '1001': '城市合伙人发起人',
        '1002': '准城市合伙人',
        '1003': '合格城市合伙人',
        '1004': '金牌城市合伙人',
        '1005': '钻石城市合伙人'
      }
      return levelObject[level]

It looks advanced and simple!

Guess you like

Origin blog.csdn.net/YZ_ZZZ24/article/details/124741484