# Map type

Map<T>Type is a built-in basic type that represents a hash table.

The literal syntax is {} for empty Map<T>, or you can initialize a table in the form of {key1 = value1, key2 = value2, key3: value3, ['key4'] = value4,'key5': value5, ...} value.

Map<T> You can use the dot operator or brackets to modify and query the value of one of the indexes, such as:

let a = { name='glua', age=1 }      -- Because the type of'glua' and 1 are not the same, the type of the a variable is automatically derived as the Map<object> type
let a1 = { name: 'glua', age: 1 }   -- Here a1 and a are equivalent to two ways of initializing Map
let a2 = { name: 'glua', address: 'China' }   -- Because the types of'glua' and'China' are both strings, the type of the a2 variable is automatically derived as Map<string>
let a3 = {name: 'glua', 'age': 1 }   -- This method is equivalent to a, a1
a['abc'] = 'China'    -- Insert/modify the value corresponding to the index ‘abc’ for a
a.abc = 'China'    -- Same effect as a['abc'] ='China'
let b1 = a.name     -- Read the value corresponding to the'name' index of a and assign it to the new variable b1
let b2 = a['name']    -- Same as let b2 = a.name

Map<T> The addition, deletion and modification of the value of the type can be operated using the built-in module table module

E.g:

var a = {name='glua'}
let b1 = a.name  -- Get the value of the key mapping of'name' in hash table a
let b2 = a['name']  -- Another way to get the value mapped by the key'name' in the hash table a
a.name = 'China'  -- Modify or add the key "name" in the hash table a to map to "China"
a['name'] = 'China'  -- Another way to modify or add the key "name" in the hash table a to "China"
var k: string, v: string = '', ''
for k, v in pairs(a) do
    pprint(k, v)  -- Traverse the hash table a, k and v are the key and value of each item of the hash table a
end