Key Facts
- Category
- Data Processing
- Input Types
- textarea, number
- Output Type
- text
- Sample Coverage
- 4
- API Ready
- Yes
Overview
The Slice Array tool extracts a segment from a JSON array using start and end indices. It leverages lodash's _.slice method for accurate slicing, supports negative indices for reverse counting, and outputs the result in JSON format.
When to Use
- •When you need to extract a specific range of elements from a JSON array.
- •When working with arrays where indices might be negative, such as getting the last few items.
- •When automating data processing tasks that involve array manipulation.
How It Works
- •Input a valid JSON array into the designated textarea field.
- •Specify the start index (default is 0) and optionally the end index (exclusive).
- •The tool applies lodash _.slice to the array based on the provided indices.
- •It returns the sliced array as a JSON string for further use.
Use Cases
Examples
1. Extract First Five Elements
Data Scientist- Background
- You have a JSON array containing 100 data points and want to examine the first five for initial analysis.
- Problem
- Manually copying elements is inefficient and prone to mistakes.
- How to Use
- Enter the array in the input field, set start to 0 and end to 5.
- Outcome
- The tool returns the first five elements as a JSON array, ready for review.
2. Get Last Three Items with Negative Index
Software Developer- Background
- Processing an array from a database query and need the last three records for a summary report.
- Problem
- Calculating the exact index for the end of the array can be cumbersome.
- How to Use
- Input the array, set start to -3 and leave end empty or set to null.
- Outcome
- The tool uses negative indexing to return the last three elements as a JSON array.
Try with Samples
jsonRelated Hubs
FAQ
What is the default value for the start index?
The default start index is 0.
Can I use negative indices?
Yes, negative indices are supported, counting from the end of the array.
What happens if I don't specify an end index?
If end is not specified, the slice goes to the end of the array.
Is the input array validated?
The tool expects a valid JSON array; invalid input may cause errors.
In what format is the result returned?
The result is returned as a JSON array string.