> For the complete documentation index, see [llms.txt](https://javascriptuse.gitbook.io/javascript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://javascriptuse.gitbook.io/javascript/problem-lay-key-dau-tien-tim-thay-chua-gia-tri-can-tim-ok.md).

# \[Problem] Lấy key đầu tiên tìm thấy chứa giá trị cần tìm (ok)

Bạn có thể sử dụng `Object.keys()` kết hợp với `find()` hoặc `filter()` để tìm key chứa giá trị cụ thể trong JavaScript. Dưới đây là cách làm:

#### Cách 1: Dùng `find()` (Trả về key đầu tiên tìm thấy)

```javascript
javascriptCopyEditconst ahash = { "one": [1, 2, 3], "two": [4, 5, 6] };

const targetNumbers = [4, 5, 6];
const key = Object.keys(ahash).find(k => ahash[k].some(num => targetNumbers.includes(num)));

console.log(key); // Kết quả: "two"
```

👉 **Lấy key đầu tiên tìm thấy chứa số cần tìm.**

***

#### Cách 2: Dùng `filter()` (Trả về tất cả các key phù hợp)

```javascript
javascriptCopyEditconst keys = Object.keys(ahash).filter(k => ahash[k].some(num => targetNumbers.includes(num)));

console.log(keys); // Kết quả: ["two"]
```

👉 **Trả về mảng chứa tất cả key thỏa mãn điều kiện.**

Bạn thích cách nào hơn? 🚀


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://javascriptuse.gitbook.io/javascript/problem-lay-key-dau-tien-tim-thay-chua-gia-tri-can-tim-ok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
