📎아이템 54 객체를 순회하는 노하우
const obj = {
one: string;
two: string;
three: string;
}
let k: keyof typeof obj; // "one" | "two" | " three"
for (k in obj) {
const v = obj[k];
}interface ABC {
a: string;
b: string;
c: number;
}
function foo(abc: ABC) {
for (const k in abc) { // const k: string
const v = abc[k];
// element: any
}
}
const x = {a: 'a', b: 'b', c: 2, d: new Date()}
foo(x); // OK📍객체 순회하기
📍 요약
Last updated