const getKeyValue =
<T extends object, U extends keyof T>(obj: T) =>
(key: U) => {
return obj[key]
}
// Usage
const list = {
1: '1',
2: '2',
3: '3',
}
getKeyValue(list)(2)
let TestObject={name:'hamza'};
let ObjectKeys=Object.key(TestObject);
console.log(ObjectKeys)
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);