1# Sorting by Indexes 2 3## When to Use 4 5When there are many options in a list, users need to slide the window to search for the target option. Sorting by indexes is here to help them quickly find the target option by way of creating an index for each option. It is actually a kind of labeling. For example, labels ABCD on the right of the contact page correspond to the initial letters of contact names. If you want to find John, clicking J will direct you to a list of names starting with J. When there are many options in a list, users need to slide the window to search for the target option. Sorting by indexes is here to help them quickly find the target option by way of creating an index for each option. 6 7## How to Develop 8 9For details about how to use related APIs, see [IndexUtil](../reference/apis-localization-kit/js-apis-i18n.md#indexutil8). 10 111. Import the **i18n** module. 12 ```ts 13 import { i18n } from '@kit.LocalizationKit'; 14 ``` 15 162. Create an **IndexUtil** object. 17 ```ts 18 let indexUtil: i18n.IndexUtil = i18n.getInstance(locale?: string); // locale is a string that indicates the locale ID. The default value is the current system locale ID. 19 ``` 20 213. Obtain the index list. 22 ```ts 23 let indexList: Array<string> = indexUtil.getIndexList(); 24 ``` 25 264. Obtain the index. 27 ```ts 28 let index: string = indexUtil.getIndex(text: string); 29 ``` 30 31**Development Example** 32 33```ts 34// Import the i18n module. 35import { i18n } from '@kit.LocalizationKit'; 36 37// Create indexes in a single language. 38let indexUtil: i18n.IndexUtil = i18n.getInstance('zh-CN'); 39let indexList: Array<string> = indexUtil.getIndexList(); // indexList = ['...', 'A', 'B', 'C', ... 'X', 'Y', 'Z', '...'] 40 41// Create indexes in multiple languages. 42indexUtil.addLocale('ru-RU'); 43// indexList = ['...', 'A', 'B', 'C', ... 'X', 'Y', 'Z', '...', 'А', 'Б', 'В', ... 'Э', 'Ю', 'Я', '...'] 44indexList = indexUtil.getIndexList(); 45 46// Obtain the index of the string. 47let index: string = indexUtil.getIndex('Nihao'); // index = 'N' 48``` 49