You’re reading the English version of this content since no translation exists yet for this locale. Help us translate this article!
שיטת
includes()
קובעת אם מערך מכיל אלמנט מסויים, מחזיר true או false בהתאם.תחביר
var boolean = array.includes(searchElement[, fromIndex])
פרמטרים
searchElement
- האלמנט אותו מחפשים
fromIndex
- אופציונלי. המיקום במערך בו להתחיל את החיפוש אחר searchElement. ערך שלילי יתחיל את החיפוש מהערך האחרון (array.length) + fromIndex בסדר עולה. ברירת מחדל 0.
ערך מוחזר (Return)
דוגמאות
[1, 2, 3].includes(2); // true [1, 2, 3].includes(4); // false [1, 2, 3].includes(3, 3); // false [1, 2, 3].includes(3, -1); // true [1, 2, NaN].includes(NaN); // true
פוליפיל - Polyfill
if (!Array.prototype.includes) { Array.prototype.includes = function(searchElement /*, fromIndex*/) { 'use strict'; if (this == null) { throw new TypeError('Array.prototype.includes called on null or undefined'); } var O = Object(this); var len = parseInt(O.length, 10) || 0; if (len === 0) { return false; } var n = parseInt(arguments[1], 10) || 0; var k; if (n >= 0) { k = n; } else { k = len + n; if (k < 0) {k = 0;} } var currentElement; while (k < len) { currentElement = O[k]; if (searchElement === currentElement || (searchElement !== searchElement && currentElement !== currentElement)) { // NaN !== NaN return true; } k++; } return false; }; }
מפרט
תאימות דפדפנים
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
מאפיין | Chrome | Firefox (Gecko) | Internet Explorer | Edge | Opera | Safari |
---|---|---|---|---|---|---|
תמיכה בסיסית |
47 |
43 | No support | 14279+ | 34 | 9 |
מאפיין | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
תמיכה בסיסית | No support |
47 |
43 | No support | 34 | 9 |
47 |