From 1109132f09d75da9a28b649c7677bb6ce07c40c0 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:41:45 -0500 Subject: initial commit --- .../global_objects/array/includes/index.html | 169 +++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 files/he/web/javascript/reference/global_objects/array/includes/index.html (limited to 'files/he/web/javascript/reference/global_objects/array/includes/index.html') diff --git a/files/he/web/javascript/reference/global_objects/array/includes/index.html b/files/he/web/javascript/reference/global_objects/array/includes/index.html new file mode 100644 index 0000000000..0cc6181f0d --- /dev/null +++ b/files/he/web/javascript/reference/global_objects/array/includes/index.html @@ -0,0 +1,169 @@ +--- +title: Array.prototype.includes() +slug: Web/JavaScript/Reference/Global_Objects/Array/includes +tags: + - ג'אווה סקריפט + - מערך + - פוליפיל + - פרוטוטייפ +translation_of: Web/JavaScript/Reference/Global_Objects/Array/includes +--- +
{{JSRef}}
+ +
שיטת includes() קובעת אם מערך מכיל אלמנט מסויים, מחזיר true או false בהתאם.
+ +
 
+ +

תחביר

+ +
var boolean = array.includes(searchElement[, fromIndex])
+ +

פרמטרים

+ +
+
searchElement
+
האלמנט אותו מחפשים
+
fromIndex
+
אופציונלי. המיקום במערך בו להתחיל את החיפוש אחר searchElement. ערך שלילי יתחיל את החיפוש מהערך האחרון (array.length) + fromIndex בסדר עולה. ברירת מחדל 0.
+
+ +

ערך מוחזר (Return)

+ +

{{jsxref("Boolean")}}.

+ +

דוגמאות

+ +
[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;
+  };
+}
+
+ +

מפרט

+ + + + + + + + + + + + + + + + + + + +
  מפרטסטטוסהערה
{{SpecName('ES7', '#sec-array.prototype.includes', 'Array.prototype.includes')}}{{Spec2('ES7')}}הגדרה ראשונית
{{SpecName('ESDraft', '#sec-array.prototype.includes', 'Array.prototype.includes')}}{{Spec2('ESDraft')}} 
+ +

תאימות דפדפנים

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + +
מאפייןChromeFirefox (Gecko)Internet ExplorerEdgeOperaSafari
תמיכה בסיסית +

{{CompatChrome(47)}}

+
43{{CompatNo}}14279+349
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
מאפייןAndroidAndroid WebviewFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileChrome for Android
תמיכה בסיסית{{CompatNo}} +

{{CompatChrome(47)}}

+
43{{CompatNo}}349 +

{{CompatChrome(47)}}

+
+
+ +

ראה עוד

+ + -- cgit v1.2.3-54-g00ecf