> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# toFilled es-toolkit

Creates a new array by filling part or all of it with the specified value.

```typescript
const filled = toFilled(arr, value, start?, end?);
```

## Usage

### `toFilled(arr, value, start?, end?)`

Use `toFilled` when you want to fill a specific range of an array with a specified value. It creates and returns a new array without modifying the original array.

```typescript
import { toFilled } from 'es-toolkit/array';

const array = [1, 2, 3, 4, 5];

// Fill with '*' from index 2 to the end.
toFilled(array, '*', 2);
// Returns: [1, 2, '*', '*', '*']

// Fill with '*' from index 1 to before index 4.
toFilled(array, '*', 1, 4);
// Returns: [1, '*', '*', '*', 5]
```

If you omit the start and end positions, it fills the entire array.

```typescript
import { toFilled } from 'es-toolkit/array';

const array = [1, 2, 3, 4, 5];

toFilled(array, '*');
// Returns: ['*', '*', '*', '*', '*']
```

You can also use negative indices. They count from the end of the array.

```typescript
import { toFilled } from 'es-toolkit/array';

const array = [1, 2, 3, 4, 5];

// Fill with '*' from 4th from the end to before 1st from the end.
toFilled(array, '*', -4, -1);
// Returns: [1, '*', '*', '*', 5]
```

#### Parameters


arrT[]required

The original array to base on.


valueUrequired

The value to fill the array with.


startnumberoptional

The start position for filling. Default is `0`.


endnumberoptional

The end position for filling. Default is the array length.

#### Returns

Returns a new array with the specified range filled with the value. The original array is not modified.

```typescript
Array<T | U>
```


Source: es-toolkit

Re-exported verbatim from [`es-toolkit`](https://es-toolkit.dev/reference/array/toFilled.html). Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.
