Categories

Fill Array

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

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]
  1. Fill entire array:
  • Input: [null, null, null]
  • Value: "filled"
  • Start: 0, End: (leave empty)
  • Output: ["filled", "filled", "filled"]
  1. With JSON parsing:
  • Input: [1, 2, 3]
  • Value: true (with parseValueAsJSON checked)
  • Output: [true, true, true] (boolean, not string)

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

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.

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

json

Related 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.

API Documentation

Request Endpoint

POST /en/api/tools/fill-array

Request Parameters

Parameter Name Type Required Description
array textarea Yes -
value text Yes -
start number No -
end number No -
parseValueAsJSON checkbox No -

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-fill-array": {
      "name": "fill-array",
      "description": "Fill array with value from start to end index using lodash _.fill",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=fill-array",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]