# generaltranslation: General Translation Core SDK: formatListToParts URL: https://generaltranslation.com/en-US/docs/core/class/methods/formatting/format-list-to-parts.mdx --- title: formatListToParts description: API reference for the formatListToParts method to format lists into parts while preserving original types --- ## Overview The `formatListToParts` method formats an array into locale-specific parts, inserting string separators between items while preserving the original types of each element. Unlike `formatList`, which returns a flat string, this method returns an `Array` — making it ideal for mixed-type arrays containing strings, numbers, objects, or JSX elements. ```typescript const gt = new GT({ locales: ['en'] }); const parts = gt.formatListToParts(['apple', 42, { type: 'fruit' }]); // Returns: ['apple', ', ', 42, ', and ', { type: 'fruit' }] ``` ## Reference ### Parameters | Name | Type | Description | |------|------|-------------| | `array` | `Array` | The array of items to format | | `options?` | `ListFormatPartsOptions` | Optional formatting configuration | ### ListFormatPartsOptions Extends `Intl.ListFormatOptions` with additional locale specification: | Name | Type | Description | |------|------|-------------| | `locales?` | `string \| string[]` | Override locales for formatting (defaults to instance locales) | | `type?` | `'conjunction' \| 'disjunction' \| 'unit'` | List formatting type (default: `'conjunction'`) | | `style?` | `'long' \| 'short' \| 'narrow'` | List formatting style (default: `'long'`) | ### Returns `Array` - An array of the original items interleaved with locale-specific string separators. --- ## Examples ### Basic list formatting ```typescript copy import { GT } from 'generaltranslation'; const gt = new GT({ locales: ['en'] }); // Conjunction (default) — "and" list console.log(gt.formatListToParts(['A', 'B', 'C'])); // Output: ['A', ', ', 'B', ', and ', 'C'] // Disjunction — "or" list console.log(gt.formatListToParts(['A', 'B', 'C'], { type: 'disjunction' })); // Output: ['A', ', ', 'B', ', or ', 'C'] ``` ### Mixed-type arrays ```typescript copy // Numbers and objects are preserved console.log(gt.formatListToParts(['apple', 42, { type: 'fruit' }])); // Output: ['apple', ', ', 42, ', and ', { type: 'fruit' }] ``` ### Style variations ```typescript copy // Short style console.log(gt.formatListToParts(['first', 'second'], { style: 'short' })); // Output: ['first', ' & ', 'second'] // Unit style console.log(gt.formatListToParts(['1km', '2mi'], { type: 'unit' })); // Output: ['1km', ', ', '2mi'] ``` ### Locale-specific formatting ```typescript copy // Spanish disjunction console.log(gt.formatListToParts(['red', 'green', 'blue'], { locales: ['es'], type: 'disjunction' })); // Output: ['red', ', ', 'green', ' o ', 'blue'] ``` --- ## Notes * Original item types are preserved — only string separators are inserted between elements * This is the key differentiator from `formatList`, which returns a flat `string` * Particularly useful for rendering mixed-type arrays in UI frameworks like React * The method uses browser-native `Intl.ListFormat` under the hood * `type: 'conjunction'` produces "and" lists, `'disjunction'` produces "or" lists, and `'unit'` produces unit-style lists ## Next steps * Check out [`Intl.ListFormat` documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat) for more options * See [`format-num`](/docs/core/class/methods/formatting/format-num) for number formatting * See standalone [`format-list-to-parts`](/docs/core/functions/formatting/format-list-to-parts) for use without GT instance * See [`format-message`](/docs/core/class/methods/formatting/format-message) for message formatting with list interpolation