Skip to content

[zh-TW]: update Array.prototype.find() #26882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 23, 2025
Merged

[zh-TW]: update Array.prototype.find() #26882

merged 4 commits into from
Apr 23, 2025

Conversation

Dr-XYZ
Copy link
Contributor

@Dr-XYZ Dr-XYZ commented Apr 18, 2025

Description

Motivation

Additional details

Related issues and pull requests

@Dr-XYZ Dr-XYZ requested a review from a team as a code owner April 18, 2025 09:05
@Dr-XYZ Dr-XYZ requested review from irvin and removed request for a team April 18, 2025 09:05
@github-actions github-actions bot added the l10n-zh Issues related to Chinese content. label Apr 18, 2025
Copy link
Contributor

github-actions bot commented Apr 18, 2025

Preview URLs

External URLs (2)

URL: /zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/find
Title: Array.prototype.find()

(comment last updated: 2025-04-23 05:19:35)

---

{{JSRef}}

**`find()`** 方法會回傳第一個滿足所提供之測試函式的元素**值**。否則回傳 {{jsxref("undefined")}}。
{{jsxref("Array")}} 實例的 **`find()`** 方法會回傳在提供的陣列中,第一個通過所提供測試函式的元素。如果沒有任何值通過測試函式,則回傳 {{jsxref("undefined")}}。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得 {{jsxref("Array")}} 實例的 **find()** 方法會回傳在提供的陣列中,第一個通過所提供測試函式的元素 中间的逗号有点割裂语义

`callback` 函式被呼叫時會傳入三個參數:元素的值、元素索引,以及正被迭代的陣列物件。

如果提供 `thisArg` 參數予 `find`,其將會被當作 `callback` 每次被呼叫的 `this`。若是沒提供,則會使用 {{jsxref("undefined")}}。
`find()` 方法是一個[迭代方法](/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array#迭代方法)。它會以索引遞增順序對陣列中的每個元素執行一次所提供的 `callbackFn` 函式,直到 `callbackFn` 回傳一個 [truthy](/zh-TW/docs/Glossary/Truthy) 值。此時,`find()` 會回傳該元素並停止迭代陣列。若 `callbackFn` 未曾回傳 truthy 值,則 `find()` 會回傳 {{jsxref("undefined")}}。請參閱[迭代方法](/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array#迭代方法)部分以深入了解這些方法的運作方式。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一样的

- {{jsxref("Array.prototype.every()")}} – test all elements together
- [在 `core-js` 中 `Array.prototype.find` 的 Polyfill](https://github.com/zloirock/core-js#ecmascript-array)
- [`Array.prototype.find` 的 es-shims polyfill](https://www.npmjs.com/package/array.prototype.find)
- [索引集合](/zh-TW/docs/Web/JavaScript/Guide/Indexed_collections)教學
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guide是翻译为教学还是指引还是指南

@github-project-automation github-project-automation bot moved this from Review requested to In progress - PRs in MDN translated-content l10n-zh Apr 22, 2025
Co-authored-by: A1lo <yin199909@aliyun.com>
@Dr-XYZ Dr-XYZ requested a review from yin1999 April 22, 2025 12:01
@yin1999 yin1999 merged commit 00a8cb2 into mdn:main Apr 23, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from In progress - PRs to Done in MDN translated-content l10n-zh Apr 23, 2025
@Dr-XYZ Dr-XYZ deleted the p4 branch April 23, 2025 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
l10n-zh Issues related to Chinese content.
Projects
Development

Successfully merging this pull request may close these issues.

2 participants