const documentObj = { days: document.getElementById('days'), hours: document.getElementById('hours'), min: document.getElementById('min'), sec: document.getElementById('sec'), } for(let key in documentObj){ console.log(key) }
객체에 사용
지정한 객체의 키값을 받아옴.
변수이기에 key가 아닌 a 이런식으로 입력해도 정상 동작함.
const documentArr = ['days','hours', 'min','sec']; for(let tag of documentArr){ console.log(tag) }for in 과 생긴건 거의 비슷하지만 객체가 아닌 배열등에 사용함.