# Sorted Unique

Remove duplicates from a sorted array using lodash _.sortedUniq

> Canonical page: https://elysiatools.com/en/tools/sorted-unique

- **Category:** Data Processing

- **Keywords:** array, unique, sorted, dedupe, lodash

## Overview

Remove consecutive duplicates from a sorted JSON array.

**Highlights:**
- Uses lodash `_.sortedUniq`
- Works on sorted arrays
- Returns the unique values as JSON

**Example:**
- Array: `[1, 1, 2, 2, 3]`
- Result: `[1, 2, 3]`

## Inputs

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

## When to use

- When you have a pre-sorted array and need to eliminate duplicate entries.
- To optimize data storage by removing redundant values in sorted lists.
- Before performing operations that require unique elements, such as set operations or analysis.

## How it works

- Input a JSON array that is already sorted in ascending order.
- The tool applies the lodash _.sortedUniq function to identify and remove consecutive duplicates.
- It returns a new JSON array containing only the unique values in their original order.

## Use cases

- Cleaning sorted log files to remove repeated entries.
- Preparing sorted lists of IDs or codes for database operations.
- Optimizing sorted arrays in data pipelines to reduce memory usage.

## Frequently asked questions

### What does the Sorted Unique tool do?

It removes consecutive duplicate values from a sorted JSON array using lodash _.sortedUniq.

### Does the array need to be sorted?

Yes, the tool requires the input array to be sorted for _.sortedUniq to work correctly.

### What input format is accepted?

You must provide a valid JSON array, such as [1, 1, 2, 3].

### Can it handle non-numeric data?

Yes, it works with any data type that can be compared, as long as the array is sorted.

### Is the original array modified?

No, the tool returns a new array with duplicates removed, leaving the input unchanged.

## Related tools

- [Compact Array](https://elysiatools.com/en/tools/compact-array): Remove falsey values from array using lodash _.compact
- [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
- [Pull Values](https://elysiatools.com/en/tools/pull-values): Remove specific values from an array using lodash _.pull
- [Sorted Unique By](https://elysiatools.com/en/tools/sorted-unique-by): Remove duplicates from a sorted array using lodash _.sortedUniqBy
- [Uniq Array](https://elysiatools.com/en/tools/uniq-array): Remove duplicates from an array using lodash _.uniq
- [Uniq By](https://elysiatools.com/en/tools/uniq-by): Remove duplicates from an array using lodash _.uniqBy with a property path
- [Without Values](https://elysiatools.com/en/tools/without-values): Remove specified values from an array using lodash _.without

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