Get to know MDN better
此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2016年8月.
includes() 方法會判斷陣列是否包含特定的元素,並以此來回傳 true 或 false。
要搜尋的元素。
fromIndex 選擇性要於此陣列中開始搜尋 searchElement 的位置。如為負數值,則自 array.length + fromIndex 開始向後搜尋。預設值為 0。
布林值(Boolean)。
如果 fromIndex大於或等於陣列長度, 會回傳false. 此陣列將不會被搜尋.
If fromIndex is negative, the computed index is calculated to be used as a position in the array at which to begin searching for searchElement. If the computed index is less than 0, the entire array will be searched.
includes() method is intentionally generic. It does not require this value to be an Array object, so it can be applied to other kinds of objects (e.g. array-like objects). The example below illustrates includes() method called on the function's arguments object.
If you need to support truly obsolete JavaScript engines that don't support Object.defineProperty, it's best not to polyfill Array.prototype methods at all, as you can't make them non-enumerable.
| ECMAScript® 2027 Language Specification # sec-array.prototype.includes |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年7月14日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.