# table type

The table type is a built-in basic type. Each table value contains two parts: an array part and a hash table. The index of the array part starts from 1. The record type also behaves as a table type at runtime.

The literal syntax is {} for an empty table, or a table value can be initialized in the form {key1 = value1, key2 = value2, ['key3'] = value3, ... }.

Table can use dot operator or brackets to modify and query the value of an index, such as:

let a = { name='glua', age=1 }
a[1] = 123   -- Add a value of 123 to the array part of a
a['abc'] = 'China'    -- Insert/modify the value corresponding to index ‘abc’ into the hash table part of a
a.abc = 'China'    -- Same effect as a[‘abc’]
let b1 = a.name     -- Read the value corresponding to the "name" index of the hash table part of a and assign it to the new variable b1
let b2 = a['name']    -- Same as a.name
let b3 = a[1]             -- Read the first value of the array part of a and assign it to the new variable b3