diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:17 -0500 |
| commit | da78a9e329e272dedb2400b79a3bdeebff387d47 (patch) | |
| tree | e6ef8aa7c43556f55ddfe031a01cf0a8fa271bfe /files/it/web/javascript/reference/global_objects/set | |
| parent | 1109132f09d75da9a28b649c7677bb6ce07c40c0 (diff) | |
| download | translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.gz translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.bz2 translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.zip | |
initial commit
Diffstat (limited to 'files/it/web/javascript/reference/global_objects/set')
3 files changed, 621 insertions, 0 deletions
diff --git a/files/it/web/javascript/reference/global_objects/set/entries/index.html b/files/it/web/javascript/reference/global_objects/set/entries/index.html new file mode 100644 index 0000000000..367507d3d5 --- /dev/null +++ b/files/it/web/javascript/reference/global_objects/set/entries/index.html @@ -0,0 +1,113 @@ +--- +title: Set.prototype.entries() +slug: Web/JavaScript/Reference/Global_Objects/Set/entries +translation_of: Web/JavaScript/Reference/Global_Objects/Set/entries +--- +<div>{{JSRef}}</div> + +<p>Il metodo <code><strong>entries()</strong></code> restituisce un novo oggetto <code>Iterator</code> che contiene<strong> un array di <code>[valore, valore]</code></strong> per ciascun elemento nell'oggetto <code>Set</code>, nell'ordine con cui sono stati inseriti. Per gli oggetti di tipo <code>Set</code> non esiste alcuna <code>chiave</code> come per gli oggetti di tipo <code>Map</code>. Comunque, per mantenere le API simili a quelle dell'oggetto <code>Map</code>, per ciascun <em>elemento</em> dell'array viene utilizzato <em>value</em> anche per la <em>chiave</em>, perciò viene restituito un array <code>[valore, valore]</code>.</p> + +<h2 id="Sintassi">Sintassi</h2> + +<pre class="syntaxbox"><code><em>mySet</em>.entries()</code></pre> + +<h3 id="Valore_restituito">Valore restituito</h3> + +<p>Un nuovo oggetto <code>Iterator</code> che contiene un array di <code>[valore, valore]</code> per ciascun elemento nell'oggetto <code>Set</code>, nell'ordine con cui sono stati inseriti.</p> + +<h2 id="Esempi">Esempi</h2> + +<h3 id="Uso_di_entries()">Uso di <code>entries()</code></h3> + +<pre class="brush:js">var mySet = new Set(); +mySet.add("foobar"); +mySet.add(1); +mySet.add("baz"); + +var setIter = mySet.entries(); + +console.log(setIter.next().value); // ["foobar", "foobar"] +console.log(setIter.next().value); // [1, 1] +console.log(setIter.next().value); // ["baz", "baz"] +</pre> + +<h2 id="Specifiche">Specifiche</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specifiche</th> + <th scope="col">Stato</th> + <th scope="col">Commenti</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-set.prototype.entries', 'Set.prototype.entries')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Initial definition.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-set.prototype.entries', 'Set.prototype.entries')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilità_browser">Compatibilità browser</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>38</td> + <td>{{ CompatGeckoDesktop("24") }}</td> + <td>{{CompatNo}}</td> + <td>25</td> + <td>7.1</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>38</td> + <td>{{ CompatGeckoMobile("24") }}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>8</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Vedi_anche">Vedi anche</h2> + +<ul> + <li>{{jsxref("Set.prototype.keys()")}}</li> + <li>{{jsxref("Set.prototype.values()")}}</li> +</ul> diff --git a/files/it/web/javascript/reference/global_objects/set/index.html b/files/it/web/javascript/reference/global_objects/set/index.html new file mode 100644 index 0000000000..c8de5d83f6 --- /dev/null +++ b/files/it/web/javascript/reference/global_objects/set/index.html @@ -0,0 +1,394 @@ +--- +title: Set +slug: Web/JavaScript/Reference/Global_Objects/Set +translation_of: Web/JavaScript/Reference/Global_Objects/Set +--- +<div>{{JSRef}}</div> + +<div>L'oggetto <strong>Set</strong> permette di memorizzare valori <em>unici </em>di qualunque tipo, che siano {{Glossary("Primitive", "valori primitivi")}} o riferimenti ad oggetti.</div> + +<div> </div> + +<h2 id="Sintassi">Sintassi</h2> + +<pre class="syntaxbox">new Set([iterabile]);</pre> + +<h3 id="Parametri">Parametri</h3> + +<dl> + <dt>iterabile</dt> + <dd>Se un <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...of">oggetto iterabile</a> è passato, tutti i suoi elementi saranno aggiunti al nuovo Set. null viene trattato come undefined.</dd> +</dl> + +<h2 id="Descrizione">Descrizione</h2> + +<p>Gli oggetti <code>Set</code> sono collezioni di valori, e possibile iterare i valori nel loro ordine di inserimento. Un valore in un <code>Set</code> può occorrere solo una volta; è quindi unico nella collezione.</p> + +<h3 id="Uguaglianza_dei_valori">Uguaglianza dei valori</h3> + +<p>Dato che ogni valore in un Set deve essere unico, dovra essere controllata l'uguaglianza di un nuovo valore con valori già presenti nel Set, questa operazione non è basata sullo stesso algoritmo usato per l'operatore ===. Nello specifico, per i Set, +0 (che è strettamente uguale a -0) e -0 sono valori differenti. Comunque, questo è stato cambiato nell'ultima specifica ECMAScript 6. Partendo da Gecko 29.0 {{geckoRelease("29")}} ({{bug("952870")}}) e da questa <a href="https://code.google.com/p/v8/issues/detail?id=3069">recente nightly Chrome issue</a>, +0 e -0 sono trattati come valori identici nell'oggetto <code>Set</code>. Inoltre, <code>NaN</code> e <code>undefined</code> possono essere memorizzati nei Set. <code>NaN</code> è considerato unguale a <code>NaN</code> (anche se <code>NaN</code> !== <code>NaN</code>).</p> + +<h2 id="Proprietà">Proprietà</h2> + +<dl> + <dt><code>Set.size</code></dt> + <dd>Il valore della proprietà <strong><font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">size </span></font></strong>è 0. </dd> + <dt>{{jsxref("Set.@@species", "get Set[@@species]")}}</dt> + <dd>Il costruttore della funzione che viene usato per creare oggetti derivati.</dd> + <dt>{{jsxref("Set.prototype")}}</dt> + <dd>Rappresenta il prototipo per il costruttore del <code>Set</code>. Consente l'aggiunta di proprietà a tutti gli oggetti <code>Set</code>.</dd> +</dl> + +<h2 id="Instanze_Set"><code>Instanze Set</code></h2> + +<p>Tutte le instanze di <code>Set</code> ereditano da {{jsxref("Set.prototype")}}.</p> + +<h3 id="Proprietà_2">Proprietà</h3> + +<p>{{page('it-IT/Web/JavaScript/Reference/Global_Objects/Set/prototype','Properties')}}</p> + +<h3 id="Methods">Methods</h3> + +<p>{{page('it-IT/Web/JavaScript/Reference/Global_Objects/Set/prototype','Methods')}}</p> + +<h2 id="Esempi">Esempi</h2> + +<h3 id="Uso_dell'oggetto_Set">Uso dell'oggetto <code>Set</code></h3> + +<pre class="brush: js">var mySet = new Set(); + +mySet.add(1); +mySet.add(5); +mySet.add("some text"); +var o = {a: 1, b: 2}; +mySet.add(o); + +mySet.has(1); // true +mySet.has(3); // false, 3 non è stato aggiunto al set +mySet.has(5); // true +mySet.has(Math.sqrt(25)); // true +mySet.has("Some Text".toLowerCase()); // true +mySet.has(o); // true + +mySet.size; // 4 + +mySet.delete(5); // rimuove 5 dal set +mySet.has(5); // false, 5 è stato rimosso + +mySet.size; // 3, abbiamo rimosso 1 valore +</pre> + +<h3 id="Iterando_oggetti_Set">Iterando oggetti Set</h3> + +<pre class="brush: js">// iterando i valori in un set +// logga gli item in ordine: 1, "testo di esempio" +for (let item of mySet) console.log(item); + +// logga gli item in ordine: 1, "testo di esempio" +for (let item of mySet.keys()) console.log(item); + +// logga gli item in ordine: 1, "testo di esempio" +for (let item of mySet.values()) console.log(item); + +// logga gli item in ordine: 1, "testo di esempio" +//(chiavi e valori qui sono uguali) +for (let [key, value] of mySet.entries()) console.log(key); + +// converte un set in un Array semplice (con ) +// convert set to plain Array (con <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Array_comprehensions">Array comprehensions</a>) +var myArr = [v for (v of mySet)]; // [1, "some text"] +// Alternativa (con <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from">Array.from</a>) +var myArr = Array.from(mySet); // [1, "some text"] + +// Il seguente snippet funzionerà anche in un documento HTML +mySet.add(document.body); +mySet.has(document.querySelector("body")); // true + +// conversione tra Set e Array +mySet2 = new Set([1,2,3,4]); +mySet2.size; // 4 +[...mySet2]; // [1,2,3,4] + +// l'itersezione può essere simulata con +var intersection = new Set([...set1].filter(x => set2.has(x))); + +// la differenza può essere simulata con +var difference = new Set([...set1].filter(x => !set2.has(x))); + +// Itera i valori di un set con forEach +mySet.forEach(function(value) { + console.log(value); +}); + +// 1 +// 2 +// 3 +// 4</pre> + +<h3 id="Relazione_con_gli_oggetti_Array">Relazione con gli oggetti <code>Array</code></h3> + +<pre class="brush: js">var myArray = ["value1", "value2", "value3"]; + +// Uso del costruttore di Set per trasformare un Array in un Set +var mySet = new Set(myArray); + +mySet.has("value1"); // ritorna true + +// Usa l'operatore spread per trasformare un Set in un Array +console.log(uneval([...mySet])); // Mostrerà lo stesso identico Array di myArray</pre> + +<h2 id="Specifica">Specifica</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-set-objects', 'Set')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Initial definition.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-set-objects', 'Set')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td> + <p>{{ CompatChrome(38) }} [1]</p> + </td> + <td>{{ CompatGeckoDesktop("13") }}</td> + <td>{{ CompatIE("11") }}</td> + <td>25</td> + <td>7.1</td> + </tr> + <tr> + <td>Constructor argument: <code>new Set(iterable)</code></td> + <td>{{ CompatChrome(38) }}</td> + <td>{{ CompatGeckoDesktop("13") }}</td> + <td>{{CompatNo}}</td> + <td>25</td> + <td>{{CompatNo}}</td> + </tr> + <tr> + <td>iterable</td> + <td>{{ CompatChrome(38) }}</td> + <td>{{ CompatGeckoDesktop("17") }}</td> + <td>{{CompatNo}}</td> + <td>25</td> + <td>7.1</td> + </tr> + <tr> + <td><code>Set.clear()</code></td> + <td>{{ CompatChrome(38) }}</td> + <td>{{CompatGeckoDesktop("19")}}</td> + <td>{{ CompatIE("11") }}</td> + <td>25</td> + <td>7.1</td> + </tr> + <tr> + <td><code>Set.keys(), Set.values(), Set.entries()</code></td> + <td>{{ CompatChrome(38) }}</td> + <td>{{CompatGeckoDesktop("24")}}</td> + <td>{{CompatNo}}</td> + <td>25</td> + <td>7.1</td> + </tr> + <tr> + <td><code>Set.forEach()</code></td> + <td>{{ CompatChrome(38) }}</td> + <td>{{CompatGeckoDesktop("25")}}</td> + <td>{{ CompatIE("11") }}</td> + <td>25</td> + <td>7.1</td> + </tr> + <tr> + <td>Value equality for -0 and 0</td> + <td>{{ CompatChrome(38) }}</td> + <td>{{CompatGeckoDesktop("29")}}</td> + <td>{{CompatNo}}</td> + <td>25</td> + <td>{{CompatNo}}</td> + </tr> + <tr> + <td>Constructor argument: <code>new Set(null)</code></td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop("37")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td>Monkey-patched <code>add()</code> in Constructor</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop("37")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>Set[@@species]</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoDesktop("41")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>Set()</code> without <code>new</code> throws</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoDesktop("42")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(38)}} [1]</td> + <td>{{ CompatGeckoMobile("13") }}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>8</td> + </tr> + <tr> + <td>Constructor argument: <code>new Set(iterable)</code></td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(38)}}</td> + <td>{{ CompatGeckoMobile("13") }}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + <tr> + <td>iterable</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{ CompatGeckoMobile("17") }}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>8</td> + </tr> + <tr> + <td><code>Set.clear()</code></td> + <td>{{CompatNo}}</td> + <td>{{ CompatChrome(38) }}</td> + <td>{{CompatGeckoMobile("19")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>8</td> + </tr> + <tr> + <td><code>Set.keys(), Set.values(), Set.entries()</code></td> + <td>{{CompatNo}}</td> + <td>{{ CompatChrome(38) }}</td> + <td>{{CompatGeckoMobile("24")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>8</td> + </tr> + <tr> + <td><code>Set.forEach()</code></td> + <td>{{CompatNo}}</td> + <td>{{ CompatChrome(38) }}</td> + <td>{{CompatGeckoMobile("25")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>8</td> + </tr> + <tr> + <td>Value equality for -0 and 0</td> + <td>{{CompatNo}}</td> + <td>{{ CompatChrome(38) }}</td> + <td>{{CompatGeckoMobile("29")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + <tr> + <td>Constructor argument: <code>new Set(null)</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("37")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td>Monkey-patched <code>add()</code> in Constructor</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("37")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>Set[@@species]</code></td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile("41")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + <tr> + <td><code>Set()</code> without <code>new</code> throws</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile("42")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] La caratteristica è disponibile come opzione da Chrome 31. In <code>chrome://flags</code>, attivare la voce “Enable Experimental JavaScript”.</p> + +<h2 id="Guarda_pure">Guarda pure</h2> + +<ul> + <li>{{jsxref("Map")}}</li> + <li>{{jsxref("WeakMap")}}</li> + <li>{{jsxref("WeakSet")}}</li> +</ul> diff --git a/files/it/web/javascript/reference/global_objects/set/values/index.html b/files/it/web/javascript/reference/global_objects/set/values/index.html new file mode 100644 index 0000000000..e662f3d62d --- /dev/null +++ b/files/it/web/javascript/reference/global_objects/set/values/index.html @@ -0,0 +1,114 @@ +--- +title: Set.prototype.values() +slug: Web/JavaScript/Reference/Global_Objects/Set/values +translation_of: Web/JavaScript/Reference/Global_Objects/Set/values +--- +<div>{{JSRef}}</div> + +<p>Il metodo <code><strong>values()</strong></code> restituisce un nuovo oggetto di tipo <code><strong>Iterator</strong></code> che contiene tutti i valori presenti nell'oggetto <code>Set</code>, nell'ordine con cui sono stati inseriti.</p> + +<p>Il metodo <strong><code>keys()</code></strong> è un alias per questo metodo (in modo da mantenere api simili all'oggetto {{jsxref("Map")}}); si comporta esattamente allo stesss modo e restiuisce i <strong>valori</strong> contenuti nell'oggetto <code>Set</code>.</p> + +<h2 id="Sintassi">Sintassi</h2> + +<pre class="syntaxbox"><code><em>mySet</em>.values(); +</code></pre> + +<h3 id="Valore_restituito">Valore restituito</h3> + +<p>Un nuovo oggetto di tipo <code><strong>Iterator</strong></code> che contiene tutti i valori presenti nell'oggetto <code>Set</code>, nell'ordine con cui sono stati inseriti.</p> + +<h2 id="Esempi">Esempi</h2> + +<h3 id="Uso_di_values()">Uso di <code>values()</code></h3> + +<pre class="brush:js">var mySet = new Set(); +mySet.add("foo"); +mySet.add("bar"); +mySet.add("baz"); + +var setIter = mySet.values(); + +console.log(setIter.next().value); // "foo" +console.log(setIter.next().value); // "bar" +console.log(setIter.next().value); // "baz"</pre> + +<h2 id="Specifiche">Specifiche</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specifiche</th> + <th scope="col">Stato</th> + <th scope="col">Commenti</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-set.prototype.values', 'Set.prototype.values')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Initial definition.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-set.prototype.values', 'Set.prototype.values')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilità_browser">Compatibilità browser</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>38</td> + <td>{{CompatGeckoDesktop("24")}}</td> + <td>{{CompatNo}}</td> + <td>25</td> + <td>7.1</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>38</td> + <td>{{ CompatGeckoMobile("24") }}</td> + <td>{{ CompatNo}}</td> + <td>{{ CompatNo}}</td> + <td>8</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Vedi_anche">Vedi anche</h2> + +<ul> + <li>{{jsxref("Set.prototype.entries()")}}</li> +</ul> |
