按深度扁平化数组
使用 lodash _.flattenDepth 按指定深度扁平化数组
将数组扁平化到指定的深度级别(嵌套扁平化到指定级别)。
## 功能特性:
- 接受任意深度的深层嵌套 JSON 数组
- 可自定义扁平化深度(1-10 级)
- 精确控制扁平化级别
- 处理混合数据类型的数组
- 使用 lodash _.flattenDepth 进行受控扁平化
## 示例:
- 深度 1:[1, [2, [3, [4]]], 5] → [1, 2, [3, [4]], 5]
- 深度 2:[1, [2, [3, [4]]], 5] → [1, 2, 3, [4], 5]
- 深度 3:[1, [2, [3, [4]]], 5] → [1, 2, 3, 4, 5]
## 使用场景:
- **受控转换**:扁平化到特定级别同时保留更深层结构
- **数据处理**:逐级处理嵌套数组
- **部分扁平化**:减少嵌套而不丢失所有结构
- **渐进式操作**:在特定嵌套级别应用转换
API 文档
请求端点
POST /zh/api/tools/flatten-depth-array
请求参数
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| array | textarea | 是 | 输入包含深层嵌套元素的有效 JSON 数组 |
| depth | number | 否 | 要扁平化的级别数(1-10) |
响应格式
{
"result": "Processed text content",
"error": "Error message (optional)",
"message": "Notification message (optional)",
"metadata": {
"key": "value"
}
}
文本:
文本
AI MCP 文档
将此工具添加到您的 MCP 服务器配置中:
{
"mcpServers": {
"elysiatools-flatten-depth-array": {
"name": "flatten-depth-array",
"description": "使用 lodash _.flattenDepth 按指定深度扁平化数组",
"baseUrl": "https://elysiatools.com/mcp/sse?toolId=flatten-depth-array",
"command": "",
"args": [],
"env": {},
"isActive": true,
"type": "sse"
}
}
}
你可以串联多个工具,比如:`https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`,最多20个。
如果遇见问题,请联系我们:[email protected]