In ﯼﺍﺮﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ


فهرست مطالب

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


For In ﻪﻘﻠﺣ

:ﺪﻧﺯ ﯽﻣ ﻪﻘﻠﺣ ءﯽﺷ ﮏﯾ ﺕﺎﯿﺻﻮﺼﺧ ﻖﯾﺮﻃ ﺯﺍ for in

ﻮﺤﻧ

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>

ﺪﺷ ﻩﺩﺍﺩ ﺢﯿﺿﻮﺗ ﻝﺎﺜﻣ

  • ﺩﻮﺷ ﯽﻣ ﺭﺍﺮﮑﺗ ﺺﺨﺷ ﯽﺷ ﮏﯾ ﯼﻭﺭ for in ﻪﻘﻠﺣ

  • ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ b> (x)/>ﺪﯿﻠﮐ ﮏﯾ ﺭﺍﺮﮑﺗ ﺮﻫ

  • ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺪﯿﻠﮐ ﺭﺍﺪﻘﻣ ﻪﺑ ﯽﺳﺮﺘﺳﺩ ﯼﺍﺮﺑ ﺪﯿﻠﮐ

  • ﺖﺳﺍ person[x] ﺪﯿﻠﮐ ﺭﺍﺪﻘﻣ


ﯼﺍﺮﺑ 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()

.ﺪﻨﮐ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺍﺭ (ﺱﺎﻤﺗ ﻪﺑ ﺦﺳﺎﭘ ﻊﺑﺎﺗ ﮏﯾ) ﻊﺑﺎﺗ ﮏﯾ ﺭﺎﺑ ﮏﯾ ﻪﯾﺍﺭﺁ ﺮﺼﻨﻋ ﺮﻫ ﯼﺍﺮﺑ

ﻝﺎﺜﻣ

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>

:ﺩﺮﯿﮔ ﯽﻣ ﻥﺎﻣﻮﮔﺭﺁ 3 ﻊﺑﺎﺗ ﻪﮐ ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

:ﺩﺮﮐ ﯽﺴﯾﻮﻧﺯﺎﺑ ﺍﺭ ﻥﺁ ﻥﺍﻮﺗ ﯽﻣ .ﺪﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺭﺍﺪﻘﻣ ﺮﺘﻣﺍﺭﺎﭘ ﺯﺍ ﻂﻘﻓ ﻻﺎﺑ ﻝﺎﺜﻣ

ﻝﺎﺜﻣ

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>

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