.ﺖﺳﺍ ﺩﺮﻓ ﻪﺑ ﺮﺼﺤﻨﻣ ﺮﯾﺩﺎﻘﻣ ﺯﺍ ﯼﺍ ﻪﻋﻮﻤﺠﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﻋﻮﻤﺠﻣ
.ﺪﻫﺩ ﺥﺭ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺭﺩ ﺭﺎﺑ ﮏﯾ ﺪﻧﺍﻮﺗ ﯽﻣ ﻂﻘﻓ ﺭﺍﺪﻘﻣ ﺮﻫ
.ﺩﺭﺍﺩ ﻪﮕﻧ ﺩﻮﺧ ﺭﺩ ﺍﺭ ﯼﺍ ﻩﺩﺍﺩ ﻉﻮﻧ ﺮﻫ ﺯﺍ ﺭﺍﺪﻘﻣ ﺮﻫ ﺪﻧﺍﻮﺗ ﯽﻣ ﻪﻋﻮﻤﺠﻣ ﮏﯾ
ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺪﯾﺪﺟ ﻪﻋﻮﻤﺠﻣ ﮏﯾ
ﺪﻨﮐ ﯽﻣ ﻪﻓﺎﺿﺍ ﻪﻋﻮﻤﺠﻣ ﻪﺑ ﺪﯾﺪﺟ ﺮﺼﻨﻋ ﮏﯾ
ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺯﺍ ﺍﺭ ﺮﺼﻨﻋ ﮏﯾ
ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ true ،ﺭﺍﺪﻘﻣ ﺩﻮﺟﻭ ﺕﺭﻮﺻ ﺭﺩ
ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺯﺍ ﺍﺭ ﺮﺻﺎﻨﻋ ﻡﺎﻤﺗ
ﺪﻨﮐ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﯽﻧﺍﻮﺧﺍﺮﻓ ﮏﯾ ﺮﺼﻨﻋ ﺮﻫ ﯼﺍﺮﺑ
ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ Set ﮏﯾ ﺮﯾﺩﺎﻘﻣ ﻡﺎﻤﺗ ﺎﺑ ﺍﺭ Iterator ﮏﯾ
()ﺮﯾﺩﺎﻘﻣ ﺪﻨﻧﺎﻤﻫ
ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺯﺍ [value,value] ﯼﺎﻫﺖﻔﺟ ﺎﺑ ﺍﺭ Iterator ﮏﯾ
ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺭﺩ ﺍﺭ ﯼﺩﺪﻋ ﺮﺻﺎﻨﻋ
:ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ
New Set()
ﻪﺑ ﻪﯾﺍﺭﺁ ﮏﯾ ﻝﺎﺳﺭﺍ
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺮﯾﺩﺎﻘﻣ ﻥﺩﺮﮐ ﻪﻓﺎﺿﺍ ﯼﺍﺮﺑ add()
ﺯﺍ ﻭ ﺪﯿﻨﮐ
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺎﻫﺮﯿﻐﺘﻣ ﻥﺩﻭﺰﻓﺍ ﯼﺍﺮﺑ add()
ﺯﺍ ﻭ ﺪﯿﻨﮐ ﺩﺎ
Set()
ﺪﯾﺪﺟ ﺵﻭﺭ :new Set()
ﻩﺪﻧﺯﺎﺳ ﻪﺑ ﻪﯾﺍﺭﺁ ﮏﯾ ﻝﺎﺳﺭﺍ
// Create a Set
const letters = new Set(["a","b","c"]);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Sets</h2>
<p>Create a Set from an Array:</p>
<p id="demo"></p>
<script>
// Create a Set
const letters = new Set(["a","b","c"]);
// Display set.size
document.getElementById("demo").innerHTML = letters.size;
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﯽﻈﻔﻠﻟﺍ ﺖﺤﺗ ﺮﯾﺩﺎﻘﻣ ﻭ ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ ﻪﻋﻮﻤﺠﻣ ﮏﯾ
// Create a Set
const letters = new Set();
// Add Values to the Set
letters.add("a");
letters.add("b");
letters.add("c");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Sets</h2>
<p>Add values to a Set:</p>
<p id="demo"></p>
<script>
// Create a Set
const letters = new Set();
// Add Values to the Set
letters.add("a");
letters.add("b");
letters.add("c");
// Display set.size
document.getElementById("demo").innerHTML = letters.size;
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﺍﺭ ﺎﻫﺮﯿﻐﺘﻣ ﻭ ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ ﻪﻋﻮﻤﺠﻣ ﮏﯾ
// Create Variables
const a = "a";
const b = "b";
const c = "c";
// Create a Set
const letters = new Set();
// Add Variables to the Set
letters.add(a);
letters.add(b);
letters.add(c);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Sets</h2>
<p>Add variables to a Set:</p>
<p id="demo"></p>
<script>
// Create a Set
const letters = new Set();
// Create Variables
const a = "a";
const b = "b";
const c = "c";
// Add the Variables to the Set
letters.add(a);
letters.add(b);
letters.add(c);
// Display set.size
document.getElementById("demo").innerHTML = letters.size;
</script>
</body>
</html>
add()
ﺵﻭﺭletters.add("d");
letters.add("e");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Sets</h2>
<p>Adding new elements to a Set:</p>
<p id="demo"></p>
<script>
// Create a new Set
const letters = new Set(["a","b","c"]);
// Add a new Element
letters.add("d");
letters.add("e");
// Display set.size
document.getElementById("demo").innerHTML = letters.size;
</script>
</body>
</html>
:ﺩﻮﺷ ﯽﻣ ﻩﺮﯿﺧﺫ ﯽﻟﻭﺍ ﻂﻘﻓ ،ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﯼﻭﺎﺴﻣ ﺮﺻﺎﻨﻋ ﺮﮔﺍ
letters.add("a");
letters.add("b");
letters.add("c");
letters.add("c");
letters.add("c");
letters.add("c");
letters.add("c");
letters.add("c");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Sets</h2>
<p>Adding equal elements to a Set:</p>
<p id="demo"></p>
<script>
// Create a Set
const letters = new Set();
// Add values to the Set
letters.add("a");
letters.add("b");
letters.add("c");
letters.add("c");
letters.add("c");
letters.add("c");
letters.add("c");
letters.add("c");
// Display set.size
document.getElementById("demo").innerHTML = letters.size;
</script>
</body>
</html>
forEach()
ﺵﻭﺭ:ﺪﻨﮐ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﻪﻋﻮﻤﺠﻣ ﺮﺼﻨﻋ ﺮﻫ ﯼﺍﺮﺑ ﺍﺭ ﻊﺑﺎﺗ ﮏﯾ forEach()
// Create a Set
const letters = new Set(["a","b","c"]);
// List all entries
let text = "";
letters.forEach (function(value) {
text += value;
})
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Sets</h2>
<p>forEach() calls a function for each element:</p>
<p id="demo"></p>
<script>
// Create a Set
const letters = new Set(["a","b","c"]);
// List all Elements
let text = "";
letters.forEach (function(value) {
text += value + "<br>";
})
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
values()
ﺵﻭﺭ:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺮﯾﺩﺎﻘﻣ ﻡﺎﻤﺗ ﯼﻭﺎﺣ Iterator ﯽﺷ ﮏﯾ v
letters.values() // Returns [object Set Iterator]
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Sets</h2>
<p>Set.values() returns a Set Iterator:</p>
<p id="demo"></p>
<script>
// Create a Set
const letters = new Set(["a","b","c"]);
// Display set.size
document.getElementById("demo").innerHTML = letters.values();
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺮﺻﺎﻨﻋ ﻪﺑ ﯽﺳﺮﺘﺳﺩ ﯼﺍﺮﺑ Iterator ﯽﺷ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﻥﻮﻨﮐﺍ
// Create an Iterator
const myIterator = letters.values();
// List all Values
let text = "";
for (const entry of myIterator) {
text += entry;
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Sets</h2>
<p>Iterating Set values:</p>
<p id="demo"></p>
<script>
// Create a Set
const letters = new Set(["a","b","c"]);
// List all Elements
let text = "";
for (const x of letters.values()) {
text += x + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
keys()
ﺵﻭﺭ.ﺩﺭﺍﺪﻧ ﺪﯿﻠﮐ ﻪﻋﻮﻤﺠﻣ ﮏﯾ
keys()
ﯽﻣﺮﺑ ﺍﺭ ﻥﺎﻤﻫﺪﻧﺍﺩﺮﮔ
.ﺪﻧﻮﺷ ﺭﺎﮔﺯﺎﺳ Maps ﺎﺑ ﺎﻫ ﻪﻋﻮﻤﺠﻣ ﺩﻮﺷ ﯽﻣ ﺚﻋﺎﺑ ﻦﯾﺍ
letters.keys() // Returns [object Set Iterator]
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Sets</h2>
<p>Set.keys() returns a Set Iterator:</p>
<p id="demo"></p>
<script>
// Create a Set
const letters = new Set(["a","b","c"]);
// Display set.size
document.getElementById("demo").innerHTML = letters.keys();
</script>
</body>
</html>
entries()
ﺵﻭﺭ.ﺩﺭﺍﺪﻧ ﺪﯿﻠﮐ ﻪﻋﻮﻤﺠﻣ ﮏﯾ
entries()
ﺖﻔﺟﯼﺎﻫ [value,value] ﯽﻣﺮﺑ ﺍﺭﺪﻧﺍﺩ
:ﺪﻧﻮﺷ ﺭﺎﮔﺯﺎﺳ Maps ﺎﺑ ﺎﻫﻪﻋﻮﻤﺠﻣ ﺩﻮﺷﯽﻣ ﺚﻋﺎﺑ ﻦﯾﺍ
// Create an Iterator
const myIterator = letters.entries();
// List all Entries
let text = "";
for (const entry of myIterator) {
text += entry;
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Sets</h2>
<p>entries() Returns an Iterator with [value,value] pairs from a Set:</p>
<p id="demo"></p>
<script>
// Create a Set
const letters = new Set(["a","b","c"]);
// List all entries
const iterator = letters.entries();
let text = "";
for (const entry of iterator) {
text += entry + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
:ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ ءﯽﺷ ﻉﻮﻧ<"code class="w3-codespan> ،ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﯼﺍﺮﺑ
typeof letters; // Returns object
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Sets Objects</h2>
<p>The typeof operator returns object:</p>
<p id="demo"></p>
<script>
// Create a new Set
const letters = new Set(["a","b","c"]);
// Display typeof
document.getElementById("demo").innerHTML = typeof letters;
</script>
</body>
</html>
:ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ true/>ﻪﻋﻮﻤﺠﻣ ﺯﺍ ﻪﻧﻮﻤﻧ<"code class="w3-codespan> ،ﻪﻋﻮﻤﺠﻣ ﮏﯾ
letters instanceof Set; // Returns true
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Sets</h2>
<p>The instanceof operator returns true:</p>
<p id="demo"></p>
<script>
// Create a new Set
const letters = new Set(["a","b","c"]);
// Display typeof
document.getElementById("demo").innerHTML = letters instanceof Set;
</script>
</body>
</html>