Source: https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/data-types/list-type/ Documentation version: v5.3.2 # List types The list type is a constructed data type that can be declared using the keyword `LIST` or `ARRAY`, where `E` represents the data type of the list elements, which can be any predefined or constructed data type other than records and paths. A list is an ordered collection of elements that can be accessed by their positions. The elements of a list must be of the same data type. For example, a list of integers cannot contain a string value. ## List indexing List indexing is the process of accessing elements in a list by their positions, which are called list indexes. The index of a list starts from 0. The first element from left to right is at index 0, the second element is at index 1, and so on. Negative indexes can be used to access elements from the end of the list. The last element is at index -1, the second-to-last element is at index -2, and so on. If an index is out of range, `NULL` is returned. ### Examples ```` LET l=[1,2,4,5] RETURN l[10%5] AS a , l[-1] AS b, l[100] AS c ```` ## List slicing List slicing is the process of extracting a subset of elements from a list. The syntax for list slicing is `list[start:end:step]`, where `start` is the index of the first element to include, `end` is the index of the last element to include, and `step` is the step size. All three parameters are optional. If `start` is not specified, the default value is 0. If `end` is not specified, the default value is the length of the list. If `step` is not specified, the default value is 1. The value of `step` cannot be 0. If the value of `step` is negative, the list is traversed in reverse order. An empty list is returned in the following cases: - The value of `step` is positive and the value of `start` is greater than the value of `end`. - The value of `start` is greater than the length of the list. - The value of `start` is negative and its absolute value is greater than the length of the list. ### Examples ```` LET l=[0,1,2,3,4] RETURN l[0:2] AS a, l[0::2] AS b, l[::] AS c, l[::-2] AS d, l[-1:-3:-1] AS e, l[1:0] AS f, l[1:1] AS g, l[6:10] AS h ```` ## Declaration example ```` ''' CREATE GRAPH TYPE IF NOT EXISTS person AS { NODE Person ( { id INT64 PRIMARY KEY, is_adult BOOL DEFAULT TRUE, name STRING DEFAULT 'John Doe', hobbies LIST DEFAULT ['reading', 'swimming'], birthday DATE DEFAULT DATE('1990-01-01') } ) } ''' ```` In the preceding example, the property `hobbies` is of the list type (`LIST`), and the data type of the list elements is string (`STRING`). The default value is `['reading', 'swimming']`. ## More information [List functions](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/functions/list/)