📜  typescript 对象按键获取值 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:20.535000             🧑  作者: Mango

代码示例1
myObj = {
  policy: {
    index: 1,
    page: "/policy"
  },
  purchase: {
    index: 2,
    page: "/purchase"
  }
}

// get value on key
Object.keys(myObj).forEach(key => {
    if (myObj[key].index === 2) {
        console.log("Found.");
    }
});

// If you want to stop the search when one was found
Object.keys(myObj).some(key => myObj[key].index === 2);