For In
ﻪﻘﻠﺣ:ﺪﻧﺯ ﯽﻣ ﻪﻘﻠﺣ ءﯽﺷ ﮏﯾ ﺕﺎﯿﺻﻮﺼﺧ ﻖﯾﺮﻃ ﺯﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﺩﻮﺷ ﯽﻣ ﺭﺍﺮﮑﺗ ﺺﺨﺷ ﯽﺷ ﮏﯾ ﯼﻭﺭ for in ﻪﻘﻠﺣ ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ b> (x)/>ﺪﯿﻠﮐ ﮏﯾ ﺭﺍﺮﮑﺗ ﺮﻫ ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺪﯿﻠﮐ ﺭﺍﺪﻘﻣ ﻪﺑ ﯽﺳﺮﺘﺳﺩ ﯼﺍﺮﺑ ﺪﯿﻠﮐ ﺖﺳﺍ person[x] ﺪﯿﻠﮐ ﺭﺍﺪﻘﻣ :ﺪﻧﺰﺑ ﻪﻘﻠﺣ ﻪﯾﺍﺭﺁ ﮏﯾ ﯼﺎﻫﯽﮔﮋﯾﻭ ﯼﻭﺭ ﺪﻧﺍﻮﺗﯽﻣ ﻦﯿﻨﭽﻤﻫ ﻮﺤﻧ
for (key in object) {
// code block to be executed
}
ﻝﺎﺜﻣ
const person = {fname:"John", lname:"Doe", age:25};
let text = "";
for (let x in person) {
text += person[x];
}
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript For In Loop</h2>
<p>The for in statement loops through the properties of an object:</p>
<p id="demo"></p>
<script>
const person = {fname:"John", lname:"Doe", age:25};
let txt = "";
for (let x in person) {
txt += person[x] + " ";
}
document.getElementById("demo").innerHTML = txt;
</script>
</body>
</html>
ﺪﺷ ﻩﺩﺍﺩ ﺢﯿﺿﻮﺗ ﻝﺎﺜﻣ
ﯼﺍﺮﺑ In
Over Arrays ﻮﺤﻧ
for (variable in array) {
code
}
const numbers = [45, 4, 9, 16, 25];
let txt = "";
for (let x in numbers) {
txt += numbers[x];
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>For In Loops</h2>
<p>The for in statement can loops over array values:</p>
<p id="demo"></p>
<script>
const numbers = [45, 4, 9, 16, 25];
let txt = "";
for (let x in numbers) {
txt += numbers[x] + "<br>";
}
document.getElementById("demo").innerHTML = txt;
</script>
</body>
</html>
.ﺪﯿﻨﮑﻧ ﻩﺩﺎﻔﺘﺳﺍ ﻪﯾﺍﺭﺁ ﯼﻭﺭ for in ﺯﺍ ،ﺖﺳﺍ ﻢﻬﻣ ﺐﯿﺗﺮﺗ ﺖﺳﺮﻬﻓ ﺮﮔﺍ
.ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺪﻧ ﯽﺳﺮﺘﺳﺩ ﻪﯾﺍﺭﺁ ﺮﯾﺩﺎﻘﻣ ﻪﺑ ﺪﯾﺭﺍﺩ ﺭﺎﻈﺘﻧﺍ ﻪﮐ ﯽﺒﯿﺗﺮﺗ ﻪﺑ ﺖﺳﺍ ﻦﮑﻤﻣ ﻭ ﺖﺳﺍ ﯼﺯﺎﺳ ﻩﺩ
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ Array.forEach() ﺎﯾ for ﻪﻘﻠﺣ ،for ﻪﻘﻠﺣ ﺯﺍ ﺖﺳﺍ ﺮﺘﻬﺑ
Array.forEach()
.ﺪﻨﮐ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺍﺭ (ﺱﺎﻤﺗ ﻪﺑ ﺦﺳﺎﭘ ﻊﺑﺎﺗ ﮏﯾ) ﻊﺑﺎﺗ ﮏﯾ ﺭﺎﺑ ﮏﯾ ﻪﯾﺍﺭﺁ ﺮﺼﻨﻋ ﺮﻫ ﯼﺍﺮﺑ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺩﺮﯿﮔ ﯽﻣ ﻥﺎﻣﻮﮔﺭﺁ 3 ﻊﺑﺎﺗ ﻪﮐ ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ ﺩﺭﻮﻣ ﺵﺯﺭﺍ ﻢﺘﯾﺁ ﺺﺧﺎﺷ ﻪﯾﺍﺭﺁ ﺩﻮﺧ :ﺩﺮﮐ ﯽﺴﯾﻮﻧﺯﺎﺑ ﺍﺭ ﻥﺁ ﻥﺍﻮﺗ ﯽﻣ .ﺪﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺭﺍﺪﻘﻣ ﺮﺘﻣﺍﺭﺎﭘ ﺯﺍ ﻂﻘﻓ ﻻﺎﺑ ﻝﺎﺜﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﻝﺎﺜﻣ
const numbers = [45, 4, 9, 16, 25];
let txt = "";
numbers.forEach(myFunction);
function myFunction(value, index, array) {
txt += value;
}
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The forEach() Method</h2>
<p>Call a function once for each array element:</p>
<p id="demo"></p>
<script>
const numbers = [45, 4, 9, 16, 25];
let txt = "";
numbers.forEach(myFunction);
document.getElementById("demo").innerHTML = txt;
function myFunction(value, index, array) {
txt += value + "<br>";
}
</script>
</body>
</html>
ﻝﺎﺜﻣ
const numbers = [45, 4, 9, 16, 25];
let txt = "";
numbers.forEach(myFunction);
function myFunction(value) {
txt += value;
}
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The forEach() Method</h2>
<p>Call a function once for each array element:</p>
<p id="demo"></p>
<script>
const numbers = [45, 4, 9, 16, 25];
let txt = "";
numbers.forEach(myFunction);
document.getElementById("demo").innerHTML = txt;
function myFunction(value) {
txt += value + "<br>";
}
</script>
</body>
</html>