ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻪﻋﻮﻤﺠﻣ


فهرست مطالب

    نمایش فهرست مطالب

.ﺖﺳﺍ ﺩﺮﻓ ﻪﺑ ﺮﺼﺤﻨﻣ ﺮﯾﺩﺎﻘﻣ ﺯﺍ ﯼﺍ ﻪﻋﻮﻤﺠﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﻋﻮﻤﺠﻣ

.ﺪﻫﺩ ﺥﺭ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺭﺩ ﺭﺎﺑ ﮏﯾ ﺪﻧﺍﻮﺗ ﯽﻣ ﻂﻘﻓ ﺭﺍﺪﻘﻣ ﺮﻫ

.ﺩﺭﺍﺩ ﻪﮕﻧ ﺩﻮﺧ ﺭﺩ ﺍﺭ ﯼﺍ ﻩﺩﺍﺩ ﻉﻮﻧ ﺮﻫ ﺯﺍ ﺭﺍﺪﻘﻣ ﺮﻫ ﺪﻧﺍﻮﺗ ﯽﻣ ﻪﻋﻮﻤﺠﻣ ﮏﯾ

ﺎﻫ ﺵﻭﺭ ﻢﯿﻈﻨﺗ

new Set()

ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺪﯾﺪﺟ ﻪﻋﻮﻤﺠﻣ ﮏﯾ

add()

ﺪﻨﮐ ﯽﻣ ﻪﻓﺎﺿﺍ ﻪﻋﻮﻤﺠﻣ ﻪﺑ ﺪﯾﺪﺟ ﺮﺼﻨﻋ ﮏﯾ

delete()

ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺯﺍ ﺍﺭ ﺮﺼﻨﻋ ﮏﯾ

has()

ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ true ،ﺭﺍﺪﻘﻣ ﺩﻮﺟﻭ ﺕﺭﻮﺻ ﺭﺩ

clear()

ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺯﺍ ﺍﺭ ﺮﺻﺎﻨﻋ ﻡﺎﻤﺗ

forEach()

ﺪﻨﮐ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﯽﻧﺍﻮﺧﺍﺮﻓ ﮏﯾ ﺮﺼﻨﻋ ﺮﻫ ﯼﺍﺮﺑ

values()

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ Set ﮏﯾ ﺮﯾﺩﺎﻘﻣ ﻡﺎﻤﺗ ﺎﺑ ﺍﺭ Iterator ﮏﯾ

keys()

()ﺮﯾﺩﺎﻘﻣ ﺪﻨﻧﺎﻤﻫ

entries()

ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺯﺍ [value,value] ﯼﺎﻫﺖﻔﺟ ﺎﺑ ﺍﺭ Iterator ﮏﯾ

size

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺭﺩ ﺍﺭ ﯼﺩﺪﻋ ﺮﺻﺎﻨﻋ


ﻢﯾﺯﺎﺴﺑ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﻪﻧﻮﮕﭼ

:ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ

  • 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>

تمامی حقوق محفوظ است. © BasicIT.org • 2023-2024