loop through the keys in an object in typescript

To loop through the keys in an object in TypeScript, you can use a for-in loop. Here's an example:

index.ts
const myObject = {
  name: 'John',
  age: 30,
  address: '123 Main St'
};

for (const key in myObject) {
  console.log(`${key}: ${myObject[key]}`);
}
150 chars
10 lines

In this example, we define an object called myObject with some properties. We then use a for-in loop to loop through the keys in the object. The key variable represents each key in the object as we iterate through them. We use this key to access the corresponding value in the object and log it to the console.

Output:

index.ts
name: John
age: 30
address: 123 Main St
40 chars
4 lines

gistlibby LogSnag