# Slice Array

Extract a section of an array using lodash _.slice

> Canonical page: https://elysiatools.com/en/tools/slice-array

- **Category:** Data Processing

- **Keywords:** array, slice, segment, range, lodash

## Overview

Slice a JSON array using start and end indices.

**Highlights:**
- Uses lodash `_.slice`
- Supports negative indices
- Returns the sliced array as JSON

**Example:**
- Array: `["a", "b", "c", "d"]`
- Start: `1`
- End: `3`
- Result: `["b", "c"]`

## Inputs

- **Array** (textarea): Enter a JSON array
- **Start Index** (number): Index to start slicing (supports negative)
- **End Index** (number): Index to stop slicing (exclusive)

## 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

- Extracting a subset of data from a large JSON array for analysis.
- Handling API responses where only a portion of the array is needed.
- Preparing array data for further processing in scripts or applications.

## Frequently asked questions

### 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.

## Related tools

- [Chunk Array](https://elysiatools.com/en/tools/chunk-array): Split array into chunks of specified size using lodash _.chunk
- [Drop Items](https://elysiatools.com/en/tools/drop-items): Drop first N items from array using lodash _.drop
- [Drop Right Items](https://elysiatools.com/en/tools/drop-right-items): Drop last N items from array using lodash _.dropRight
- [From Pairs](https://elysiatools.com/en/tools/from-pairs): Convert array of key-value pairs to object using lodash _.fromPairs
- [Get Path](https://elysiatools.com/en/tools/get-path): Get a value at a path using lodash _.get
- [Group By](https://elysiatools.com/en/tools/group-by): Group items by a derived key using lodash _.groupBy
- [Has In Path](https://elysiatools.com/en/tools/has-in-path): Check if a path exists using lodash _.hasIn
- [Has Path](https://elysiatools.com/en/tools/has-path): Check if a path exists using lodash _.has

## Samples

- [Grafana Advanced Application Samples](https://elysiatools.com/en/samples/grafana-samples): Comprehensive Grafana samples covering advanced dashboard design, alerting configurations, data source integrations, and plugin development
- [QR Code Samples](https://elysiatools.com/en/samples/qrcode-samples): Sample QR code images for testing QR code reading and generation tools
- [D3.js Data Visualization Samples](https://elysiatools.com/en/samples/d3js-data-visualization): Comprehensive D3.js data visualization examples including charts, maps, animations, and interactive visualizations
- [Rome JavaScript Toolchain Samples](https://elysiatools.com/en/samples/rome): Rome JavaScript toolchain examples including configuration, linting, formatting, bundling, and project management
