Key Facts
- Category
- Data Processing
- Input Types
- textarea, number
- Output Type
- text
- Sample Coverage
- 4
- API Ready
- Yes
Overview
The Nth Item tool retrieves the element at a specified index from a JSON array using the lodash _.nth function. It supports both positive and negative indices, allowing you to access items from the start or end of the array and returns the value in JSON format.
When to Use
- •When you need to extract a specific element from an array by its position.
- •When working with arrays where negative indices are useful for counting from the end.
- •When you want a quick, reliable way to access array elements without writing custom code.
How It Works
- •Input a valid JSON array in the 'Array' field.
- •Specify the index (zero-based, negative for reverse counting) in the 'Index' field.
- •The tool uses lodash _.nth to fetch the item and outputs it as a JSON-formatted value.
Use Cases
Examples
1. Retrieve Last Transaction
- Background
- You have an array of recent transaction amounts and need the most recent one for a summary.
- Problem
- Manually counting indices to find the last element is error-prone and time-consuming.
- How to Use
- Enter the transaction array, e.g., [50, 75, 100, 125], and set the index to -1.
- Outcome
- The tool returns 125, the last transaction amount, as a JSON value.
2. Get Third User Input
- Background
- Processing a list of user-submitted answers where the third answer is critical for analysis.
- Problem
- Need to consistently extract the third element without manual indexing each time.
- How to Use
- Input the array of answers, e.g., ["yes", "no", "maybe", "unknown"], and set the index to 2.
- Outcome
- The third answer "maybe" is retrieved and displayed in JSON format.
Try with Samples
jsonRelated Hubs
FAQ
What does a negative index mean?
A negative index counts from the end of the array, where -1 is the last element.
What happens if the index is out of bounds?
The tool returns undefined for indices beyond the array length.
Can I use this with nested arrays or objects?
No, it works on a single-level array; for nested structures, use other data processing tools.
Is the index zero-based?
Yes, indices start at 0 for the first element, and negative indices count from the end.
What input format is required?
The array must be valid JSON, such as ["a", "b", "c"], and the index must be a number.