[express]객체의 프로퍼티 순회하는 법

헌치·2021년 11월 30일
0

Express

목록 보기
2/2

0. 객체? 프로퍼티?

  • 객체
객체 = {
    "id": 1,
    "name": "Alex",
    "team": "engineering",
    "position": "IOS Developer",
    "emailAddress": "alex@google.com",
    "phoneNumber": "010-xxxx-xxxx",
    "admissionDate": "2018/12/10",
    "birthday": "1994/11/08",
    "profileImage": "profile1.png"
}
  • 프로퍼티 : 각각 id, name...

1. Object.keys


Object.keys(객체).forEach((prop) => {
      console.log(객체[prop]);
    });


특정 객체의 모든 프로퍼티를 조회

2. Object.entries

각 프로퍼티의 이름(key)-값(value) 쌍을 담은 배열을 리턴하는 메소드

console.log(Object.entries(객체));

3. for ... in 구문

for (const 프로퍼티 in 객체) {
  console.log(`Key: ${프로퍼티} => Value: ${객체[프로퍼티]}`);
}


5. 참고링크

코드잇

profile
🌱 함께 자라는 중입니다 🚀 rerub0831@gmail.com

0개의 댓글