깜놀하는 해므찌로

StringMap 활용 간략 예시 본문

IT

StringMap 활용 간략 예시

agnusdei1207 2023. 8. 8. 22:44
반응형
SMALL
const stringMap: Record<string, string> = {
  MASTER: '마스터',
  CONSULTANT: '컨설턴트',
  ETC: '기타',
  ADMIN_PENDING: '승인대기',
  ADMIN_APPROVED: '승인',
  ADMIN_BLOCKED: '차단',
};

console.log(stringMap.MASTER); // Output: "마스터"
console.log(stringMap.CONSULTANT); // Output: "컨설턴트"
console.log(stringMap.ADMIN_APPROVED); // Output: "승인"
// You can access the values by using the corresponding key in the object.

// You can also iterate over the keys and values in the object:
for (const key in stringMap) {
  if (Object.prototype.hasOwnProperty.call(stringMap, key)) {
    const value = stringMap[key];
    console.log(`Key: ${key}, Value: ${value}`);
  }
}

 

반응형
LIST