typescript object get value by key

Solutions on MaxInterview for typescript object get value by key by the best coders in the world

showing results for - "typescript object get value by key"
Laura
24 Jan 2021
1myObj = {
2  policy: {
3    index: 1,
4    page: "/policy"
5  },
6  purchase: {
7    index: 2,
8    page: "/purchase"
9  }
10}
11
12// get value on key
13Object.keys(myObj).forEach(key => {
14    if (myObj[key].index === 2) {
15        console.log("Found.");
16    }
17});
18
19// If you want to stop the search when one was found
20Object.keys(myObj).some(key => myObj[key].index === 2);