# Sorted Unique By

Remove duplicates from a sorted array using lodash _.sortedUniqBy

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

- **Category:** Data Processing

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

## Overview

Remove duplicates from a sorted array using a property path.

**Highlights:**
- Uses lodash `_.sortedUniqBy`
- Supports property paths (e.g. `id`, `meta.key`)
- Returns unique values as JSON

**Example:**
- Array: `[{"id": 1}, {"id": 1}, {"id": 2}]`
- Path: `id`
- Result: `[{"id": 1}, {"id": 2}]`

## Inputs

- **Array** (textarea): Enter a JSON array
- **Property Path** (text): Property path used to compare values

## When to use

- When you have a sorted list of objects and need to eliminate duplicates based on a specific key or nested property.
- To clean up data from APIs, databases, or exports where duplicates might occur in sorted order without re-sorting.
- When preparing data for further processing, analysis, or display, ensuring uniqueness while maintaining the original sort sequence.

## How it works

- Input a JSON array that is already sorted in ascending order.
- Specify the property path to compare for duplicates, such as 'id' or 'meta.key'.
- The tool applies lodash's _.sortedUniqBy to remove consecutive duplicate entries based on the path.
- Output the resulting unique array as JSON, preserving the sort order.

## Use cases

- Deduplicating user records from a sorted database export based on user ID.
- Cleaning up sorted log entries by unique error codes or timestamps.
- Processing sorted inventory lists to remove duplicate product SKUs for accurate reporting.

## Frequently asked questions

### What input format is required?

A JSON array that must be sorted before use.

### Can I use nested property paths?

Yes, paths like 'meta.key' are supported for comparing nested values.

### What if the array is not sorted?

The tool assumes sorted input; unsorted arrays may not produce correct results.

### Is the output in JSON format?

Yes, the result is a JSON array of unique objects.

### Do I need to install lodash?

No, the tool uses lodash internally; you only provide the input array and path.

## 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](https://elysiatools.com/en/tools/sorted-unique): Remove duplicates from a sorted array using lodash _.sortedUniq
- [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
