# Head Item

Get the first element of array using lodash _.head

> Canonical page: https://elysiatools.com/en/tools/head-item

- **Category:** Data Processing

- **Keywords:** array, head, first, element, lodash, access

## Overview

Retrieve the first element from an array.

## Features:
- Gets the first element of any array
- Returns undefined for empty arrays
- Handles arrays with any data type
- Simple and straightforward operation
- Uses lodash _.head for reliable access

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

## Use Cases:
- **Quick Preview**: Preview the first item of a collection
- **Data Validation**: Check the first element of data
- **Array Processing**: Process the leading element separately
- **Queue Operations**: Peek at the front of a queue

## Inputs

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

## When to use

- When you need to preview the first item in a collection or dataset for quick inspection.
- For data validation tasks where checking the first element ensures array integrity.
- In array processing workflows that require separate handling of the leading element, such as in queues.

## How it works

- Enter a valid JSON array into the textarea input field.
- The tool applies the lodash _.head function to extract the first element from the array.
- The result is displayed as text, showing the first element or undefined if the array is empty.

## Use cases

- Previewing the first record in a JSON dataset from an API response.
- Validating that an array is not empty by checking its first element.
- Processing the front item in a queue or list for operations like peeking or dequeuing.

## Frequently asked questions

### What does the Head Item tool do?

It retrieves the first element from an array using the lodash _.head function.

### What happens if the input array is empty?

The tool returns undefined, indicating that there is no first element.

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

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

### Is there a limit to the array size?

No specific limit is imposed, but it is optimized for typical array sizes used in web applications.

### How do I use this tool?

Paste a JSON array into the input field, and the tool will output the first element as text.

## Related tools

- [Find Key](https://elysiatools.com/en/tools/find-key): Find the first matching key using lodash _.findKey
- [Get Path](https://elysiatools.com/en/tools/get-path): Get a value at a path using lodash _.get
- [Index Of](https://elysiatools.com/en/tools/index-of): Find the index of a value in array using lodash _.indexOf
- [Initial Items](https://elysiatools.com/en/tools/initial-items): Get all elements except the last using lodash _.initial
- [Nth Item](https://elysiatools.com/en/tools/nth-item): Get the item at a specific index using lodash _.nth
- [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
- [Take Items](https://elysiatools.com/en/tools/take-items): Take the first N items using lodash _.take

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