user@intzzzero:~/blog$ls -la[05:44]
$cat "Data Structure - Dictionary.md"
5027 bytes[Computer Science]2020.06.15.
═══════════════════════════════════════════════════════════

Dictionary

Dictionarykey : value가 쌍을 이루는 형태의 자료구조를 말하며, hash map 또는 hash table이라고도 부른다. 자바스크립트에서는 객체와 JSON이 이러한 형태를 지니고 있다.

위와 같은 Dictionary의 자료구조를 만드는 방법으로 자바스크립트에는 아래와 같이 세 가지 방법이 있다.

// how to make dictionary
// 1. literal
dictionary1 = { name: [ 'Ryan', 'Lee' ], job: 'sw engineer', address: { city: 'seoul', zip_code: '1234' } };

// 2. assignement to empty object
dictionary2 = {};
dictionary2['name'] = [ 'Ryan', 'Lee' ];
dictionary2['job'] = 'sw engineer';
dictionary2['address'] = { city: 'seoul', zip_code: '1234' };

// 3. Object method
let dictionary3 = Object({ name: [ 'Ryan', 'Lee' ], job: 'sw engineer', address: { city: 'seoul', zip_code: '1234' } });

위의 Dictionary 세 개를 각각 콘솔에 출력해보면 모두 동일한 형태와 내용을 지녔음을 알 수 있다.

참고: - 자바스크립트에서 hash table의 내부구조