.ﺪﻨﺷﺎﺑ ﯼﺍ ﻩﺩﺍﺩ ﻉﻮﻧ ﺮﻫ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﺎﻫﺪﯿﻠﮐ ﻥﺁ ﺭﺩ ﻪﮐ ﺩﺭﺍﺩ ﯽﻣ ﻪﮕﻧ ﺩﻮﺧ ﺭﺩ ﺍﺭ ﺭﺍﺪﻘﻣ-ﺪﯿﻠﮐ ﯼﺎﻫ
.ﺩﺭﻭﺁ ﯽﻣ ﺮﻃﺎﺧ ﻪﺑ ﺍﺭ ﺎﻫﺪﯿﻠﮐ ﯽﻠﺻﺍ ﺝﺭﺩ ﺐﯿﺗﺮﺗ ﻪﺸﻘﻧ
.ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﺍﺭ ﻪﺸﻘﻧ ﻩﺯﺍﺪﻧﺍ ﻪﮐ ﺖﺳﺍ ﯽﮔﮋﯾﻭ ﯼﺍﺭﺍﺩ ﻪﺸﻘﻧ
ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺪﯾﺪﺟ Map ﯽﺷ ﮏﯾ
ﺪﻨﮐ ﯽﻣ ﻦﯿﯿﻌﺗ ﻪﺸﻘﻧ ﺭﺩ ﺍﺭ ﺪﯿﻠﮐ ﮏﯾ ﺭﺍﺪﻘﻣ
ﺪﻨﮐ ﯽﻣ ﺖﻓﺎﯾﺭﺩ ﻪﺸﻘﻧ ﺭﺩ ﺍﺭ ﺪﯿﻠﮐ ﮏﯾ ﺭﺍﺪﻘﻣ
ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﻪﺸﻘﻧ ﺯﺍ ﺍﺭ ﺮﺻﺎﻨﻋ ﻡﺎﻤﺗ
ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﺍﺭ ﺪﯿﻠﮐ ﮏﯾ ﻂﺳﻮﺗ ﻩﺪﺷ ﺺﺨﺸﻣ ﻪﺸﻘﻧ ﺮﺼﻨﻋ ﮏﯾ
ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ true ﺭﺍﺪﻘﻣ ،ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺩﻮﺟﻭ ﻪﺸﻘﻧ ﺭﺩ ﯼﺪﯿﻠﮐ ﺮﮔﺍ
ﺪﻨﮐ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﯽﺘﺸﮔﺮﺑ ﺱﺎﻤﺗ ﮏﯾ ﻪﺸﻘﻧ ﺭﺩ ﺭﺍﺪﻘﻣ/ﺪﯿﻠﮐ ﺖﻔﺟ ﺮﻫ ﯼﺍﺮﺑ
ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻪﺸﻘﻧ ﺭﺩ [key, value] ﯼﺎﻫ ﺖﻔﺟ ﺎﺑ ﺍﺭ ﻩﺪﻨﻨﮐ ﺭﺍﺮﮑﺗ ﯽﺷ ﮏﯾ
ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻪﺸﻘﻧ ﺭﺩ ﺩﻮﺟﻮﻣ ﯼﺎﻫﺪﯿﻠﮐ ﺎﺑ ﺍﺭ ﻩﺪﻨﻨﮐ ﺭﺍﺮﮑﺗ ﯽﺷ ﮏﯾ
ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻪﺸﻘﻧ ﺭﺩ ﺩﻮﺟﻮﻣ ﺮﯾﺩﺎﻘﻣ ﻩﺪﻨﻨﮐ ﺭﺍﺮﮑﺗ ﯽﺷ ﮏﯾ
ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ ﻪﺸﻘﻧ ﺮﺻﺎﻨﻋ ﺩﺍﺪﻌﺗ
:ﻂﺳﻮﺗ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺸﻘﻧ ﮏﯾ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ
new Map()
ﻪﺑ ﻪﯾﺍﺭﺁ ﮏﯾ ﻝﺎﺳﺭﺍ
ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ Map.set()
ﺯﺍ ﻭ ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ ﻪﺸﻘﻧ ﮏﯾ
ﻪﺸﻘﻧ()
:ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ ﻪﺸﻘﻧ ﮏﯾ new Map()
ﻩﺪﻧﺯﺎﺳ ﻪﺑ ﻪﯾﺍﺭﺁ ﮏﯾ ﻝﺎﺳ
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Map Objects</h2>
<p>Creating a Map from an Array:</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
document.getElementById("demo").innerHTML = fruits.get("apples");
</script>
</body>
</html>
Map.set()
:ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﻪﺸﻘﻧ ﻪﺑ ﺍﺭ ﺮﺻﺎﻨﻋ set()
ﺵﻭﺭ ﺎﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ
// Create a Map
const fruits = new Map();
// Set Map Values
fruits.set("apples", 500);
fruits.set("bananas", 300);
fruits.set("oranges", 200);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Map Objects</h2>
<p>Using Map.set():</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map();
// Set Map Values
fruits.set("apples", 500);
fruits.set("bananas", 300);
fruits.set("oranges", 200);
document.getElementById("demo").innerHTML = fruits.get("apples");
</script>
</body>
</html>
:ﺩﻮﺷ ﻩﺩﺎﻔﺘﺳﺍ Map ﺩﻮﺟﻮﻣ ﺮﯾﺩﺎﻘﻣ ﺮﯿﯿﻐﺗ ﯼﺍﺮﺑ ﺪﻧﺍﻮﺗ ﯽﻣ ﻦﯿﻨﭽﻤﻫ se
fruits.set("apples", 500);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Map Objects</h2>
<p>Using Map.set():</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
fruits.set("apples", 200);
document.getElementById("demo").innerHTML = fruits.get("apples");
</script>
</body>
</html>
Map.get()
:ﺪﻨﮐ ﯽﻣ ﺖﻓﺎﯾﺭﺩ ﻪﺸﻘﻧ ﺭﺩ ﺍﺭ ﺪﯿﻠﮐ ﮏﯾ ﺭﺍﺪﻘﻣ get()
ﺪﺘﻣ
fruits.get("apples"); // Returns 500
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Map Objects</h2>
<p>Using Map.get():</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
document.getElementById("demo").innerHTML = fruits.get("apples");
</script>
</body>
</html>
Map.size
:ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ ﻪﺸﻘﻧ ﺭﺩ ﺩﻮﺟﻮﻣ ﺮﺻﺎﻨﻋ ﺩﺍﺪﻌﺗ size
ﯽ
fruits.size;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Maps</h2>
<p>Using Map.size:</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
document.getElementById("demo").innerHTML = fruits.size;
</script>
</body>
</html>
Map.delete()
:ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﺍﺭ Map ﺮﺼﻨﻋ ﮏﯾ delete()
ﺵﻭﺭ
fruits.delete("apples");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Maps</h2>
<p>Deleting Map elements:</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
// Delete an Element
fruits.delete("apples");
document.getElementById("demo").innerHTML = fruits.size;
</script>
</body>
</html>
Map.clear()
:ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﻪﺸﻘﻧ ﺯﺍ ﺍﺭ ﺮﺻﺎﻨﻋ ﻪﻤﻫ clear()
ﺵﻭﺭ
fruits.clear();
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Maps</h2>
<p>Clearing a Map:</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
// Clear the Map
fruits.clear();
document.getElementById("demo").innerHTML = fruits.size;
</script>
</body>
</html>
Map.has()
:ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ true ﺭﺍﺪﻘﻣ has()
ﺵﻭﺭ ،ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ
fruits.has("apples");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Maps</h2>
<p>Using Map.has():</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
document.getElementById("demo").innerHTML = fruits.has("apples");
</script>
</body>
</html>
fruits.delete("apples");
fruits.has("apples");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Maps</h2>
<p>Using Map.has():</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
// Delete an Element
fruits.delete("apples");
document.getElementById("demo").innerHTML = fruits.has("apples");
</script>
</body>
</html>
ﻉﻮﻧ
ﯽﻣﺮﺑ ﺍﺭ ﯽﺷﺪﻧﺍﺩﺮﮔ:
// Returns object:
typeof fruits;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Map Objects</h2>
<p>Map typeof:</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
document.getElementById("demo").innerHTML = typeof fruits;
</script>
</body>
</html>
ﻪﻧﻮﻤﻧ
Map true ﯽﻣﺮﺑ ﺍﺭﺪﻧﺍﺩﺮﮔ:
// Returns true:
fruits instanceof Map;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Map Objects</h2>
<p>Map instanceof:</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
document.getElementById("demo").innerHTML = fruits instanceof Map;
</script>
</body>
</html>
ﺭﺍﺮﮑﺗ ﻞﺑﺎﻗ ﺎﻤﯿﻘﺘﺴﻣ
ﺪﺷﺎﺑ ﻩﺯﺍﺪﻧﺍ ﺖﯿﺻﺎﺧ ﯼﺍﺭﺍﺩ
ﺪﻨﺷﺎﺑ ﯼﺍ ﻩﺩﺍﺩ ﻉﻮﻧ ﺮﻫ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﺎﻫﺪﯿﻠﮐ
ﺪﻧﻮﺷ ﯽﻣ ﺐﺗﺮﻣ ﺝﺭﺩ ﺎﺑ ﺎﻫﺪﯿﻠﮐ
ﺪﯾﺭﺍﺪﻧ ﺽﺮﻓ ﺶﯿﭘ ﯼﺎﻫﺪﯿﻠﮐ
Map.forEach()
:ﺪﻨﮐ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﯽﺘﺸﮔﺮﺑ ﺱﺎﻤﺗ ﮏﯾ ،ﻪﺸﻘﻧ ﺭﺩ ﺭﺍﺪﻘﻣ/ﺪﯿﻠﮐ ﺖﻔﺟ ﺮﻫ ﯼﺍﺮﺑ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﻝﺎﺜﻣ
// List all entries
let text = "";
fruits.forEach (function(value, key) {
text += key + ' = ' + value;
})
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Map Objects</h2>
<p>Using Map.forEach():</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
let text = "";
fruits.forEach (function(value, key) {
text += key + ' = ' + value + "<br>"
})
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
Map.entries()
:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻪﺸﻘﻧ ﺭﺩ ﺍﺭ [key,values] ﺎﺑ ﻩﺪﻨﻨﮐ ﺭﺍﺮﮑﺗ ﯽﺷ ﮏﯾ e
// List all entries
let text = "";
for (const x of fruits.entries()) {
text += x;
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Map Objects</h2>
<p>Using Map.entries():</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
let text = "";
for (const x of fruits.entries()) {
text += x + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
Map.keys()
:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻪﺸﻘﻧ ﺭﺩ ﺩﻮﺟﻮﻣ ﯼﺎﻫﺪﯿﻠﮐ ﺎﺑ ﺍﺭ ﻩﺪﻨﻨﮐ ﺭﺍﺮﮑﺗ ﯽﺷ ﮏﯾ
// List all keys
let text = "";
for (const x of fruits.keys()) {
text += x;
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Map Objects</h2>
<p>Using Map.keys():</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
let text = "";
for (const x of fruits.keys()) {
text += x + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
Map.values()
:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻪﺸﻘﻧ ﺭﺩ ﺩﻮﺟﻮﻣ ﺮﯾﺩﺎﻘﻣ ﺎﺑ ﺍﺭ ﻩﺪﻨﻨﮐ ﺭﺍﺮﮑﺗ ﯽﺷ ﮏﯾ v
// List all values
let text = "";
for (const x of fruits.values()) {
text += x;
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Map Objects</h2>
<p>Using Map.values():</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
let text = "";
for (const x of fruits.values()) {
text += x + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻪﺸﻘﻧ ﮏﯾ ﺭﺩ ﺮﯾﺩﺎﻘﻣ ﻥﺩﺮﮐ ﻊﻤﺟ ﯼﺍﺮﺑ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺖﺳﺍ ﻪﺸﻘﻧ ﻢﻬﻣ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﺯﺍ ﯽﮑﯾ ﺪﯿﻠﮐ ﻥﺍﻮﻨﻋ ﻪﺑ ءﺎﯿﺷﺍ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﯽﯾﺎﻧﺍﻮﺗ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :("ﺐﯿﺳ") ﻪﺘﺷﺭ ﮏﯾ ﻪﻧ ،ﺖﺳﺍ (ﺐﯿﺳ) ﯽﺷ ﮏﯾ ﺪﯿﻠﮐ :ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺩﺎﯾ ﻪﺑ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﺭﺭﻮﻠﭙﺴﮐﺍ ﺖﻧﺮﺘﻨﯾﺍ ﺰﺟ ﻪﺑ ﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﻤﻫ ﺭﺩ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻪﺸﻘﻧvalues()
ﻝﺎﺜﻣ
// Sum all values
let total = 0;
for (const x of fruits.values()) {
total += x;
}
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Map Objects</h2>
<p>Using Map.values():</p>
<p id="demo"></p>
<script>
// Create a Map
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
let total = 0;
for (const x of fruits.values()) {
total += x;
}
document.getElementById("demo").innerHTML = total;
</script>
</body>
</html>
ﺪﯿﻠﮐ ﻥﺍﻮﻨﻋ ﻪﺑ ءﺎﯿﺷﺍ
ﻝﺎﺜﻣ
// Create Objects
const apples = {name: 'Apples'};
const bananas = {name: 'Bananas'};
const oranges = {name: 'Oranges'};
// Create a Map
const fruits = new Map();
// Add new Elements to the Map
fruits.set(apples, 500);
fruits.set(bananas, 300);
fruits.set(oranges, 200);
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Map Objects</h2>
<p>Being able to use objects as keys is an important Map feature:</p>
<p id="demo"></p>
<script>
// Create Objects
const apples = {name: 'Apples'};
const bananas = {name: 'Bananas'};
const oranges = {name: 'Oranges'};
// Create a Map
const fruits = new Map();
// Add the Objects to the Map
fruits.set(apples, 500);
fruits.set(bananas, 300);
fruits.set(oranges, 200);
document.getElementById("demo").innerHTML = fruits.get(apples);
</script>
</body>
</html>
ﻝﺎﺜﻣ
fruits.get("apples"); // Returns undefined
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Map Objects</h2>
<p id="demo"></p>
<script>
// Create Objects
const apples = {name: 'Apples'};
const bananas = {name: 'Bananas'};
const oranges = {name: 'Oranges'};
// Create a Map
const fruits = new Map();
// Add Elements to the Map
fruits.set(apples, 500);
fruits.set(bananas, 300);
fruits.set(oranges, 200);
document.getElementById("demo").innerHTML = fruits.get("apples");
</script>
</body>
</html>
ﺮﮔﺭﻭﺮﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ
Chrome
Edge
Firefox
Safari
Opera