查找索引
使用 lodash _.indexOf 查找值在数组中的索引
查找数组中特定值的索引位置。
## 功能特性:
- 搜索值并返回其索引
- 如果未找到值,返回 -1
- 支持各种数据类型(数字、字符串、对象)
- 可选的搜索起始位置
- 使用 lodash _.indexOf 进行可靠搜索
## 示例:
- 数组:[1, 2, 3, 2],值:2 → 索引:1
- 数组:["a", "b", "c"],值:"b" → 索引:1
- 数组:[1, 2, 3],值:4 → 索引:-1(未找到)
- 数组:[1, 2, 3, 2],值:2,起始索引:2 → 索引:3
## 使用场景:
- **位置查找**:定位元素出现的位置
- **重复检测**:查找多次出现
- **验证**:检查值是否存在于数组中
- **数据分析**:分析元素位置
API 文档
请求端点
POST /zh/api/tools/index-of
请求参数
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| array | textarea | 是 | 输入要搜索的有效 JSON 数组 |
| searchValue | text | 是 | 输入要查找的值(对象/数组使用 JSON 格式) |
| fromIndex | number | 否 | 可选:从此索引开始搜索 |
响应格式
{
"result": "Processed text content",
"error": "Error message (optional)",
"message": "Notification message (optional)",
"metadata": {
"key": "value"
}
}
文本:
文本
AI MCP 文档
将此工具添加到您的 MCP 服务器配置中:
{
"mcpServers": {
"elysiatools-index-of": {
"name": "index-of",
"description": "使用 lodash _.indexOf 查找值在数组中的索引",
"baseUrl": "https://elysiatools.com/mcp/sse?toolId=index-of",
"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]