Key Facts
- Category
- Data Processing
- Input Types
- textarea, text, number, checkbox
- Output Type
- text
- Sample Coverage
- 4
- API Ready
- Yes
Overview
The Fill Array tool uses lodash's _.fill() method to populate array elements with a specified value. It allows you to control the start and end indices for partial filling and supports JSON parsing to ensure values are handled with the correct data types.
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
Examples
1. Basic Partial Fill
- Background
- A developer has an array [1, 2, 3, 4, 5] and needs to replace elements from index 1 to 3 with '*'.
- Problem
- Manually editing the array is time-consuming and error-prone.
- How to Use
- Input the array, set value to '*', start index to 1, end index to 4.
- Outcome
- The array becomes [1, '*', '*', '*', 5].
2. Fill Entire Array with String
- Background
- A user has an array of nulls [null, null, null] and wants to fill it with 'filled'.
- Problem
- Need to populate all elements with a consistent value.
- How to Use
- Input the array, set value to 'filled', leave start and end indices as default or empty.
- Outcome
- The array is transformed to ['filled', 'filled', 'filled'].
3. JSON Parsed Boolean Fill
- Background
- An array [1, 2, 3] needs to be filled with boolean true values.
- Problem
- Without JSON parsing, 'true' would be a string, not a boolean.
- How to Use
- Input the array, set value to 'true', enable 'Parse Value as JSON'.
- Example Config
-
parseValueAsJSON: true - Outcome
- The array becomes [true, true, true] with boolean values.
Try with Samples
jsonRelated Hubs
FAQ
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.