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


فهرست مطالب

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

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

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

ﯼﺭﻭﺮﺿ ﻪﻋﻮﻤﺠﻣ ﯼﺎﻬﺷﻭﺭ

new Set()

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

add()

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

delete()

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

has()

ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ true ﺭﺍﺪﻘﻣ ،ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺩﻮﺟﻭ ﻪﻋﻮﻤﺠﻣ ﺭﺩ ﯼﺭﺍﺪﻘﻣ ﺮﮔﺍ

forEach()

ﺪﻨﮐ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﯽﺘﺸﮔﺮﺑ ﺱﺎﻤﺗ ﮏﯾ ،ﻪﻋﻮﻤﺠﻣ ﺭﺩ ﺮﺼﻨﻋ ﺮﻫ ﯼﺍﺮﺑ

values()

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺭﺩ ﺩﻮﺟﻮﻣ ﺮﯾﺩﺎﻘﻣ ﻡﺎﻤﺗ ﺎﺑ ﺍﺭ ﻩﺪﻨﻨﮐ ﺭﺍﺮﮑﺗ ﮏﯾ

size

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


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

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

  • New Set() ﻪﺑ ﻪﯾﺍﺭﺁ ﮏﯾ ﻝﺎﺳﺭﺍ

  • .ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺮﯾﺩﺎﻘﻣ ﻥﺩﺮﮐ ﻪﻓﺎﺿﺍ ﯼﺍﺮﺑ add() ﺯﺍ ﻭ ﺪﯿﻨﮐ

  • .ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺎﻫﺮﯿﻐﺘﻣ ﻥﺩﻭﺰﻓﺍ ﯼﺍﺮﺑ add() ﺯﺍ ﻭ ﺪﯿﻨﮐ ﺩﺎ


new 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 a Set
const letters = new Set();

// Create Variables
const a = "a";
const b = "b";
const c = "c";

// 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 Elements
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() ﺵﻭﺭ

:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻪﻋﻮﻤﺠﻣ ﮏﯾ ﺮﯾﺩﺎﻘﻣ ﻡﺎﻤﺗ ﯼﻭﺎﺣ ﺪﯾﺪﺟ ﻩﺪﻨﻨﮐ ﺭﺍﺮﮑﺗ ﯽﺷ ﮏﯾ

ﻝﺎﺜﻣ

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 ﯽﺷ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﻥﻮﻨﮐﺍ

ﻝﺎﺜﻣ

// List all Elements
let text = "";
for (const x of letters.values()) {
  text += x;
}

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

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

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