# Find Key

Find the first matching key using lodash _.findKey

> Canonical page: https://elysiatools.com/en/tools/find-key

- **Category:** Data Processing

- **Keywords:** find, key, lodash, object, predicate

## Overview

Find the first key whose value matches a predicate.

**Highlights:**
- Uses lodash `_.findKey`
- Supports property, matchesProperty, or matches object predicates
- Returns the first matching key or null

**Example:**
- Object: `{"a":{"active":false},"b":{"active":true}}`
- Predicate Type: `Property`
- Property Name: `active`
- Result: `"b"`

## Inputs

- **Object** (textarea): Enter a JSON object
- **Predicate Type** (select)
- **Property Name** (text): Truthy property name when using property predicate
- **Match Path** (text): Property path for matchesProperty
- **Match Value** (textarea): JSON value to match
- **Match Object** (textarea): JSON object to match

## When to use

- When you need to locate the first occurrence of a key based on a specific property value.
- When filtering complex JSON structures to find an entry that matches a nested object pattern.
- When you need to verify if any item in a collection meets a criteria and retrieve its identifier.

## How it works

- Paste your JSON object into the input field.
- Select the predicate type that best fits your search criteria: Property, Matches Property, or Matches Object.
- Define the specific property name, path, or object structure to match.
- Execute the tool to return the first matching key or null if no match is found.

## Use cases

- Identifying the ID of the first user in a database export who has an 'active' status set to true.
- Locating the configuration key that matches a specific set of nested settings.
- Quickly finding a product SKU in a large inventory object based on a specific attribute match.

## Frequently asked questions

### What library does this tool use?

This tool utilizes the lodash _.findKey function to perform searches.

### What happens if no key matches the criteria?

The tool will return null.

### Can I search for nested properties?

Yes, by using the 'Matches Property' predicate type and providing the correct path.

### Does it return all matching keys?

No, it only returns the first key that satisfies the provided predicate.

### Is the input format strictly JSON?

Yes, the input must be a valid JSON object.

## Related tools

- [Count By](https://elysiatools.com/en/tools/count-by): Count items by a derived key using lodash _.countBy
- [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
- [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
- [Assign In Object](https://elysiatools.com/en/tools/assign-in-object): Assign own and inherited properties using lodash _.assignIn

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