# Fill Array

Fill array with value from start to end index using lodash _.fill

> Canonical page: https://elysiatools.com/en/tools/fill-array

- **Category:** Data Processing

- **Keywords:** array, fill, replace, populate, value, lodash

## Overview

**Fill Array Tool**

This tool uses lodash `_.fill()` method to populate array elements with a specified value.

**Features:**
- Fill array elements with any value (string, number, boolean, object)
- Specify start and end positions for partial filling
- Parse values as JSON for proper type handling
- Support for nested arrays and objects

**Examples:**

1. **Basic fill:**
   - Input: `[1, 2, 3, 4, 5]`
   - Value: `*`
   - Start: `1`, End: `4`
   - Output: `[1, '*', '*', '*', 5]`

2. **Fill entire array:**
   - Input: `[null, null, null]`
   - Value: `"filled"`
   - Start: `0`, End: (leave empty)
   - Output: `["filled", "filled", "filled"]`

3. **With JSON parsing:**
   - Input: `[1, 2, 3]`
   - Value: `true` (with parseValueAsJSON checked)
   - Output: `[true, true, true]` (boolean, not string)

## Inputs

- **Array** (textarea): \[1, 2, 3, 4, 5\]
- **Fill Value** (text): 0 or "*" or "filled"
- **Start Index** (number): 0
- **End Index** (number): Leave empty for end of array
- **Parse Value as JSON** (checkbox)

## When to use

- When you need to replace multiple array elements with a constant value.
- When you want to fill only a specific range within an array, leaving other elements unchanged.
- When you require values to be parsed as JSON to maintain proper data types, such as booleans or objects.

## How it works

- Input your array in the designated textarea.
- Specify the fill value and optionally set start and end indices.
- Enable 'Parse Value as JSON' if you need the value to be interpreted as a JSON type.
- The tool applies lodash _.fill() to generate the modified array.

## Use cases

- Initializing arrays with default values for testing or simulation.
- Masking or anonymizing data by replacing sensitive elements with placeholders.
- Preparing data structures by filling missing or placeholder values in specific positions.

## Frequently asked questions

### What types of values can I use to fill the array?

You can use any value, including strings, numbers, booleans, or objects.

### Can I fill only part of the array?

Yes, by specifying the start and end indices, you can fill a specific range.

### Does the tool support nested arrays or objects?

Yes, it supports filling with nested structures, and JSON parsing ensures correct handling.

### What happens if I don't specify an end index?

If left empty, the fill operation extends to the end of the array.

### Is there a limit to the array size?

The tool can handle arrays of various sizes, but performance may depend on your browser's capabilities.

## Related tools

- [Compact Array](https://elysiatools.com/en/tools/compact-array): Remove falsey values from array using lodash _.compact
- [Defaults Object](https://elysiatools.com/en/tools/defaults-object): Apply default values to an object using lodash _.defaults
- [Drop Items](https://elysiatools.com/en/tools/drop-items): Drop first N items from array using lodash _.drop
- [Drop Right Items](https://elysiatools.com/en/tools/drop-right-items): Drop last N items from array using lodash _.dropRight
- [Drop While](https://elysiatools.com/en/tools/drop-while): Drop items from array while predicate is true using lodash _.dropWhile
- [Flatten Depth Array](https://elysiatools.com/en/tools/flatten-depth-array): Flatten array to specified depth using lodash _.flattenDepth
- [From Pairs](https://elysiatools.com/en/tools/from-pairs): Convert array of key-value pairs to object using lodash _.fromPairs
- [Last Item](https://elysiatools.com/en/tools/last-item): Get the last item from an array using lodash _.last

## Samples

- [Distributed Tracing Samples](https://elysiatools.com/en/samples/distributed-tracing-samples): Comprehensive distributed tracing examples using Jaeger, OpenTelemetry, and other modern observability tools for microservices architecture
- [AWS EventBridge Samples](https://elysiatools.com/en/samples/eventbridge-samples): AWS EventBridge examples including event buses, rules, targets, schema registry, custom events, and cross-account event routing for serverless event-driven architecture
- [JWT Samples](https://elysiatools.com/en/samples/jwt-samples): Comprehensive JWT examples from basic token structure to advanced security implementations
- [PDF Samples](https://elysiatools.com/en/samples/pdf-samples): Generated PDF samples from tools dated 2026-02-01 to 2026-02-10
