From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- .../global_objects/array/includes/index.html | 162 +++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 files/it/web/javascript/reference/global_objects/array/includes/index.html (limited to 'files/it/web/javascript/reference/global_objects/array/includes') diff --git a/files/it/web/javascript/reference/global_objects/array/includes/index.html b/files/it/web/javascript/reference/global_objects/array/includes/index.html new file mode 100644 index 0000000000..04dc817974 --- /dev/null +++ b/files/it/web/javascript/reference/global_objects/array/includes/index.html @@ -0,0 +1,162 @@ +--- +title: Array.prototype.includes() +slug: Web/JavaScript/Reference/Global_Objects/Array/includes +translation_of: Web/JavaScript/Reference/Global_Objects/Array/includes +--- +
{{JSRef}}
+ +

Il metodo includes() determina se un array include un certo elemento, ritornando truefalse a seconda del caso

+ +

Sintassi

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

Parametri

+ +
+
searchElement
+
L'elemento da cercare.
+
fromIndex
+
Opzionale. La posizione nell'array da cui partire per cercare l'elemento searchElement. Un valore negativo ricerca dal valore di array.length + fromIndex in maniera ascendente. Il valore di default è 0.
+
+ +

Valore di ritorno

+ +

Un {{jsxref("Boolean")}}.

+ +

Examples

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

Specifications

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES7', '#sec-array.prototype.includes', 'Array.prototype.includes')}}{{Spec2('ES7')}}Definizione iniziale.
{{SpecName('ESDraft', '#sec-array.prototype.includes', 'Array.prototype.includes')}}{{Spec2('ESDraft')}} 
+ +

Browser compatibility

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerEdgeOperaSafari
Basic support +

{{CompatChrome(47)}}

+
43{{CompatNo}}14279+349
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidAndroid WebviewFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileChrome for Android
Basic support{{CompatNo}} +

{{CompatChrome(47)}}

+
43{{CompatNo}}349 +

{{CompatChrome(47)}}

+
+
+ +

Vedi anche

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