# Initial Items

Get all elements except the last using lodash _.initial

> Canonical page: https://elysiatools.com/en/tools/initial-items

- **Category:** Data Processing

- **Keywords:** array, initial, except, last, lodash, slice

## Overview

Retrieve all elements of an array except the last one.

## Features:
- Returns all elements except the last
- Returns empty array for single-element or empty arrays
- Handles arrays with any data type
- Simple and intuitive operation
- Uses lodash _.initial for reliable extraction

## Examples:
- Input: [1, 2, 3] → Output: [1, 2]
- Input: ["a", "b", "c", "d"] → Output: ["a", "b", "c"]
- Input: [{id: 1}, {id: 2}, {id: 3}] → Output: [{id: 1}, {id: 2}]
- Input: [1] → Output: []
- Input: [] → Output: []

## Use Cases:
- **Data Preparation**: Prepare data excluding the final element
- **Validation**: Validate all items except the last (e.g., footer data)
- **Batch Processing**: Process all but the last item
- **Array Manipulation**: Remove trailing elements

## Inputs

- **Array Input** (textarea): Enter a valid JSON array

## When to use

- When you need to exclude the last element from an array for further processing or analysis.
- For data validation where the final item should be ignored, such as in lists with footer entries.
- In batch processing scenarios where the last element is handled separately or removed from consideration.

## How it works

- Input a valid JSON array into the designated textarea field.
- The tool applies the lodash _.initial function to process the array.
- It returns a new array containing all elements except the last one, or an empty array if the input has one or zero elements.

## Use cases

- Preparing datasets by removing the last entry for analysis or reporting.
- Validating all items in a list except the final one, such as during data cleaning processes.
- Processing arrays in batches where the last element is not required for the current operation.

## Frequently asked questions

### What does the Initial Items tool do?

It returns all elements of an array except the last one using lodash _.initial.

### How do I use this tool?

Enter a JSON array in the input field, and the tool will output the array without the last element.

### What happens if the array is empty or has only one element?

An empty array is returned in both cases.

### Can it handle arrays with different data types?

Yes, it works with arrays containing numbers, strings, objects, or any other data type.

### Is there a way to retrieve the last element instead?

No, this tool is designed specifically to exclude the last element. Use other functions for that purpose.

## Related tools

- [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
- [Head Item](https://elysiatools.com/en/tools/head-item): Get the first element of array using lodash _.head
- [Index Of](https://elysiatools.com/en/tools/index-of): Find the index of a value in array using lodash _.indexOf
- [Nth Item](https://elysiatools.com/en/tools/nth-item): Get the item at a specific index using lodash _.nth
- [Remove By Predicate](https://elysiatools.com/en/tools/remove-by-predicate): Remove items that match a predicate using lodash _.remove
- [Sorted Index](https://elysiatools.com/en/tools/sorted-index): Find the insertion index in a sorted array using lodash _.sortedIndex
- [Tail Items](https://elysiatools.com/en/tools/tail-items): Return all but the first array item using lodash _.tail

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