Categories

Index Of

Find the index of a value in array using lodash _.indexOf

Find the index position of a specific value within an array.

Features:

  • Searches for a value and returns its index
  • Returns -1 if the value is not found
  • Supports various data types (numbers, strings, objects)
  • Optional starting position for search
  • Uses lodash _.indexOf for reliable searching

Examples:

  • Array: [1, 2, 3, 2], Value: 2 → Index: 1
  • Array: ["a", "b", "c"], Value: "b" → Index: 1
  • Array: [1, 2, 3], Value: 4 → Index: -1 (not found)
  • Array: [1, 2, 3, 2], Value: 2, FromIndex: 2 → Index: 3

Use Cases:

  • Position Finding: Locate where an element appears
  • Duplicate Detection: Find multiple occurrences
  • Validation: Check if a value exists in an array
  • Data Analysis: Analyze element positions

Enter a valid JSON array to search in

Enter the value to find (for objects/arrays use JSON format)

Optional: Start search from this index

Key Facts

Category
Data Processing
Input Types
textarea, text, number
Output Type
text
Sample Coverage
4
API Ready
Yes

Overview

The Index Of tool finds the position of a specific value within an array using lodash's _.indexOf function. It returns the index where the value is first found, or -1 if not present, supporting various data types and optional search starting points.

When to Use

  • When you need to locate the exact position of an element in an array.
  • To detect duplicate values by finding multiple occurrences in data.
  • For validating whether a value exists in a dataset before processing.

How It Works

  • Input a valid JSON array and the value you want to search for.
  • Optionally specify a starting index to begin the search from a specific position.
  • The tool uses lodash _.indexOf to scan the array and return the index.
  • If the value is not found, it returns -1 to indicate absence.

Use Cases

Finding the position of a specific item in a list for quick reference.
Identifying duplicate entries in data arrays during analysis.
Checking for the presence of a value in a collection before operations.

Examples

1. Locate Product ID in Inventory List

Background
An inventory manager has a JSON array of product IDs and needs to find where a specific ID is listed.
Problem
Manually searching through hundreds of entries is inefficient and error-prone.
How to Use
Enter the array of product IDs in the Array Input field and the target ID in Search Value.
Outcome
The tool returns the index position, enabling quick access to the product's location in the list.

2. Check for Duplicate Survey Responses

Background
A data analyst is reviewing survey responses stored in an array to identify repeated answers.
Problem
Need to detect duplicates for data cleaning without scanning the entire array manually.
How to Use
Input the array of responses and the value to check, using fromIndex to find subsequent occurrences.
Outcome
By returning the index, the tool helps pinpoint where duplicates appear, aiding in data validation.

Try with Samples

json

Related Hubs

FAQ

What does the tool return if the value is not in the array?

It returns -1 to indicate the value was not found.

Can I search for objects or nested arrays?

Yes, it supports various data types including objects and arrays, but ensure inputs are in valid JSON format.

How do I use the fromIndex option?

Enter a number to start the search from that index, skipping earlier elements in the array.

Is there a limit on array size?

The tool can handle arrays of any size, but performance may depend on your browser for very large datasets.

What format should the array input be in?

The array must be entered as a valid JSON array, such as [1, 2, 3] or ["a", "b", "c"].

API Documentation

Request Endpoint

POST /en/api/tools/index-of

Request Parameters

Parameter Name Type Required Description
array textarea Yes Enter a valid JSON array to search in
searchValue text Yes Enter the value to find (for objects/arrays use JSON format)
fromIndex number No Optional: Start search from this index

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-index-of": {
      "name": "index-of",
      "description": "Find the index of a value in array using lodash _.indexOf",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=index-of",
      "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]