ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﯽﮔﮋﯾﻭ


فهرست مطالب

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


.ﺪﻨﺘﺴﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﺮﻫ ﺶﺨﺑ ﻦﯾﺮﺘﻤﻬﻣ ﺎﻫ ﯽﮔﮋﯾﻭ


ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﯽﮔﮋﯾﻭ

.ﺪﻨﺘﺴﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﺎﺑ ﻂﺒﺗﺮﻣ ﺮﯾﺩﺎﻘﻣ ﺎﻫ ﯽﮔﮋﯾﻭ

.ﺖﺳﺍ ﺐﺗﺮﻣﺎﻧ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﺯﺍ ﯼﺍ ﻪﻋﻮﻤﺠﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ

.ﺪﻨﺘﺴﻫ ﯽﻧﺪﻧﺍﻮﺧ ﻂﻘﻓ ﯽﺧﺮﺑ ﺎﻣﺍ ،ﺩﺮﮐ ﻑﺬﺣ ﻭ ﺩﺮﮐ ﻪﻓﺎﺿﺍ ،ﺩﺍﺩ ﺮﯿﯿﻐﺗ ﺍﺭ ﺎﻫ ﯽﮔﮋﯾﻭ ﻥﺍﻮﺗ ﯽﻣ ﻻًﻮﻤﻌﻣ


ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺕﺎﯿﺻﻮﺼﺧ ﻪﺑ ﯽﺳﺮﺘﺳﺩ

:ﺖﺳﺍ ﺮﯾﺯ ﺕﺭﻮﺻ ﻪﺑ ﯽﺷ ﮏﯾ ﯽﮔﮋﯾﻭ ﻪﺑ ﯽﺳﺮﺘﺳﺩ ﯼﺍﺮﺑ ﺲﮑﺘﻨﯿﺳ

objectName.property      // person.age

ﺎﯾ

objectName["property"]   // person["age"]

ﺎﯾ

objectName[expression]   // x = "age"; person[x]

.ﺩﻮﺷ ﯽﺑﺎﯾﺯﺭﺍ ﯽﮔﮋﯾﻭ ﻡﺎﻧ ﻪﺑ ﺪﯾﺎﺑ ﺕﺭﺎﺒﻋ

1 ﻝﺎﺜﻣ

person.firstname + " is " + person.age + " years old.";

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Object Properties</h2>
<p>Access a property with .property:</p>

<p id="demo"></p>

<script>
const person = {
  firstname: "John",
  lastname: "Doe",
  age: 50,
  eyecolor: "blue"
};

document.getElementById("demo").innerHTML = person.firstname + " is " + person.age + " years old.";
</script>

</body>
</html>

2 ﻝﺎﺜﻣ

person["firstname"] + " is " + person["age"] + " years old.";

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Object Properties</h2>
<p>Access a property with ["property"]:</p>

<p id="demo"></p>

<script>
const person = {
  firstname: "John",
  lastname: "Doe",
  age: 50,
  eyecolor: "blue"
};

document.getElementById("demo").innerHTML = person["firstname"] + " is " + person["age"] + " years old.";
</script>

</body>
</html>


ﻪﻘﻠﺣ ﺭﺩ ... ﯼﺍﺮﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ

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

ﻮﺤﻧ

for (let variable in object) {
      // code to be executed
 }

.ﺩﻮﺷ ﯽﻣ ﺍﺮﺟﺍ ﯽﮔﮋﯾﻭ ﺮﻫ ﯼﺍﺮﺑ ﺭﺎﺑ ﮏﯾ for...in ﻪﻘﻠﺣ ﻞﺧﺍﺩ

:ﯽﺷ ﮏﯾ ﺕﺎﯿﺻﻮﺼﺧ ﻖﯾﺮﻃ ﺯﺍ ﻥﺩﺯ ﻪﻘﻠﺣ

ﻝﺎﺜﻣ

const person = {
  fname:" John",
  lname:" Doe",
  age: 25
};

for (let x in person) {
    txt += person[x];
 }

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Object Properties</h2>
<p>Looping object property values:</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>

ﺪﯾﺪﺟ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﻥﺩﻭﺰﻓﺍ

.ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﺪﯾﺪﺟ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ،ﺩﻮﺟﻮﻣ ءﯽﺷ ﮏﯾ ﻪﺑ ﺭﺍﺪﻘﻣ ﮏﯾ ﻥﺩﺍﺩ ﺎﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ

- ﺖﺳﺍ ﻪﺘﺷﺍﺩ ﺩﻮﺟﻭ ﻞﺒﻗ ﺯﺍ ﺺﺨﺷ ﯽﺷ ﺪﯿﻨﮐ ﺽﺮﻓ

ﻝﺎﺜﻣ

person.nationality = "English";

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Object Properties</h2>
<p>Add a new property to an existing object:</p>

<p id="demo"></p>

<script>
const person = {
  firstname: "John",
  lastname: "Doe",
  age: 50,
  eyecolor: "blue"
};

person.nationality = "English";
document.getElementById("demo").innerHTML =
person.firstname + " is " + person.nationality + ".";
</script>

</body>
</html>

ﺹﺍﻮﺧ ﻑﺬﺣ

:ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﯽﺷ ﮏﯾ ﺯﺍ ﺍﺭ ﯽﮔﮋﯾﻭ ﮏﯾ ﻑﺬﺣ<"code class="w3-codespan> ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ

ﻝﺎﺜﻣ

const person = {
  firstName: "John",
  lastName: "Doe",
  age: 50,
  eyeColor: "blue"
};

delete person.age;

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Object Properties</h2>
<p>Deleting object properties.</p>

<p id="demo"></p>

<script>
const person = {
  firstname: "John",
  lastname: "Doe",
  age: 50,
  eyecolor: "blue"
};

delete person.age;

document.getElementById("demo").innerHTML =
person.firstname + " is " + person.age + " years old.";
</script>

</body>
</html>

;["ﻦﺳ"]ﺺﺨﺷ ﻑﺬﺣ ﺎﯾ

ﻝﺎﺜﻣ

const person = {
  firstName: "John",
  lastName: "Doe",
  age: 50,
  eyeColor: "blue"
};

delete person["age"];

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Object Properties</h2>
<p>Deleting object properties.</p>

<p id="demo"></p>

<script>
const person = {
  firstname: "John",
  lastname: "Doe",
  age: 50,
  eyecolor: "blue"
};

delete person["age"];

document.getElementById("demo").innerHTML =
person.firstname + " is " + person.age + " years old.";
</script>

</body>
</html>

.ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﺍﺭ ﯽﮔﮋﯾﻭ ﺩﻮﺧ ﻢﻫ ﻭ ﯽﮔﮋﯾﻭ ﺵﺯﺭﺍ ﻢﻫ ﻑﺬﺣ<"code class="w3-codespan> ﯼﺪﯿﻠ

.ﺖﺴﯿﻧ ﻩﺩﺎﻔﺘﺳﺍ ﻞﺑﺎﻗ ﻩﺭﺎﺑﻭﺩ ﻥﺪﺷ ﻪﻓﺎﺿﺍ ﺯﺍ ﻞﺒﻗ ﯽﮔﮋﯾﻭ ،ﻑﺬﺣ ﺯﺍ ﺲﭘ

ﺍﺭ

ﺩﻮﺷ ﻩﺩﺎﻔﺘﺳﺍ ﻩﺪﺷ ﻒﯾﺮﻌﺗ ﺶﯿﭘ ﺯﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﯼﻭﺭ ﺪﯾﺎﺒﻧ ﻑﺬﺣ<"code class="w3-cod


ﻮﺗ ﺭﺩ ﻮﺗ ءﺎﯿﺷﺍ

:ﺪﻨﺷﺎﺑ ﯼﺮﮕﯾﺩ ﯽﺷ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﯽﺷ ﮏﯾ ﺭﺩ ﺩﻮﺟﻮﻣ ﺮﯾﺩﺎﻘﻣ

ﻝﺎﺜﻣ

myObj = {
  name:"John",
  age:30,
    
  cars: {
    car1:"Ford",
      
  car2:"BMW",
    car3:"Fiat"
    }
}
  

:ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﯽﺳﺮﺘﺳﺩ ﻮﺗ ﺭﺩ ﻮﺗ ءﺎﯿﺷﺍ ﻪﺑ ﺖﮐﺍﺮﺑ ﺖﻣﻼﻋ ﺎﯾ ﻪﻄﻘﻧ ﺖﻣﻼﻋ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ

ﻝﺎﺜﻣ

myObj.cars.car2;

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>
<p>Access nested objects:</p>

<p id="demo"></p>

<script>
const myObj = {
  name: "John",
  age: 30,
  cars: {
  car1: "Ford",
  car2: "BMW",
  car3: "Fiat"
  }
}
document.getElementById("demo").innerHTML = myObj.cars.car2;
</script>

</body>
</html>

: ﺎﯾ

ﻝﺎﺜﻣ

myObj.cars["car2"];

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>
<p>Access nested objects:</p>

<p id="demo"></p>

<script>
const myObj = {
  name: "John",
  age: 30,
  cars: {
  car1: "Ford",
  car2: "BMW",
  car3: "Fiat"
  }
}
document.getElementById("demo").innerHTML = myObj.cars["car2"];
</script>

</body>
</html>

: ﺎﯾ

ﻝﺎﺜﻣ

myObj["cars"]["car2"];

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>
<p>Access nested objects:</p>

<p id="demo"></p>

<script>
const myObj = {
  name: "John",
  age: 30,
  cars: {
  car1: "Ford",
  car2: "BMW",
  car3: "Fiat"
  }
}
document.getElementById("demo").innerHTML = myObj["cars"]["car2"];
</script>

</body>
</html>

: ﺎﯾ

ﻝﺎﺜﻣ

let p1 = "cars";
let p2 = "car2";
myObj[p1][p2];

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>
<p>Access nested objects:</p>

<p id="demo"></p>

<script>
const myObj = {
  name: "John",
  age: 30,
  cars: {
  car1: "Ford",
  car2: "BMW",
  car3: "Fiat"
  }
}

let p1 = "cars";
let p2 = "car2";
document.getElementById("demo").innerHTML = myObj[p1][p2];
</script>

</body>
</html>

ﻮﺗ ﺭﺩ ﻮﺗ ءﺎﯿﺷﺍ ﻭ ﺎﻫ ﻪﯾﺍﺭﺁ

:ﺪﻨﺷﺎﺑ ﺎﯿﺷﺍ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﺎﻫ ﻪﯾﺍﺭﺁ ﺭﺩ ﺩﻮﺟﻮﻣ ﺮﯾﺩﺎﻘﻣ ﻭ ﺪﻨﺷﺎﺑ ﻪﯾﺍﺭﺁ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﺎﯿﺷﺍ ﺭﺩ ﺩﻮﺟﻮﻣ

ﻝﺎﺜﻣ

const myObj =
  {
  name: "John",
  age: 30,
    
  cars: [
    {name:"Ford", 
  models:["Fiesta", "Focus", "Mustang"]},
    
  {name:"BMW", models:["320", "X3", "X5"]},
      
  {name:"Fiat", models:["500", "Panda"]}
    ]
}

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻪﯾﺍﺭﺁ ﺮﻫ ﯼﺍﺮﺑ for-in ﻪﻘﻠﺣ ﮏﯾ ﺯﺍ ،ﺎﻫ ﻪﯾﺍﺭﺁ ﻞﺧﺍﺩ ﯼﺎﻫ ﻪﯾﺍﺭﺁ ﻪﺑ ﯽﺳﺮﺘﺳﺩ ﯼﺍﺮﺑ

ﻝﺎﺜﻣ

for (let i in myObj.cars) {
  x += "<h1>" + myObj.cars[i].name 
  + "</h1>";
  for (let j in myObj.cars[i].models) {
    
  x += myObj.cars[i].models[j];
  }
}

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>Nested JavaScript Objects and Arrays.</h2>

<p id="demo"></p>

<script>
let x = "";
const myObj = {
  name: "John",
  age: 30,
  cars: [
    {name:"Ford", models:["Fiesta", "Focus", "Mustang"]},
    {name:"BMW", models:["320", "X3", "X5"]},
    {name:"Fiat", models:["500", "Panda"]}
  ]
}

for (let i in myObj.cars) {
  x += "<h2>" + myObj.cars[i].name + "</h2>";
  for (let j in myObj.cars[i].models) {
    x += myObj.cars[i].models[j] + "<br>";
  }
}

document.getElementById("demo").innerHTML = x;
</script>

</body>
</html>

ﺹﺍﻮﺧ ﯼﺎﻫ ﯽﮔﮋﯾﻭ

.ﺪﻧﺭﺍﺩ ﺰﯿﻧ ﺵﺯﺭﺍ ﮏﯾ ﺎﻬﻧﺁ ﻦﯾﺍ ﺮﺑ ﻩﻭﻼﻋ .ﺪﻧﺭﺍﺩ ﻡﺎﻧ ﮏﯾ ﮎﻼﻣﺍ ﻪﻤﻫ

.ﺖﺳﺍ ﯽﯾﺍﺭﺍﺩ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﺯﺍ ﯽﮑﯾ ﺭﺍﺪﻘﻣ

.ﻦﺘﺷﻮﻧ ﻞﺑﺎﻗ ﻭ ﻢﯿﻈﻨﺗ ﻞﺑﺎﻗ ،ﺵﺭﺎﻤﺷ ﻞﺑﺎﻗ :ﺯﺍ ﺪﻨﺗﺭﺎﺒﻋ ﺎﻫ ﯽﮔﮋﯾﻭ ﺮﯾﺎﺳ

ﺖﺳﺍ ،؟ﺖﺳﺍ ﻥﺪﻧﺍﻮﺧ ﻞﺑﺎﻗ ﺎﯾﺁ) ﺪﻨﻨﮐ ﯽﻣ ﺺﺨﺸﻣ ﺍﺭ ﯽﮔﮋﯾﻭ ﻪﺑ ﯽﺳﺮﺘﺳﺩ ﻩﻮﺤﻧ ﺎﻫ ﯽﮔﮋﯾﻭ ﻦﯾﺍ

ﺪﻧﺍﻮﺗ ﯽﻣ value ﯽﮔﮋﯾﻭ ﻂﻘﻓ ﺎﻣﺍ ،ﺪﻨﺘﺴﻫ ﻥﺪﻧﺍﻮﺧ ﻞﺑﺎﻗ ﺎﻫ ﯽﮔﮋﯾﻭ ﻪﻤﻫ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ

(ECMAScript 5 ﺖﺳﺍ ﺎﻫ ﯽﮔﮋﯾﻭ ﻡﺎﻤﺗ ﻢﯿﻈﻨﺗ ﻭ ﻦﺘﻓﺮﮔ ﯼﺍﺮﺑ ﯽﯾﺎﻫ ﺵﻭﺭ ﯼﺍﺭﺍﺩ


ﻪﯿﻟﻭﺍ ﻪﻧﻮﻤﻧ ﯼﺎﻫ ﯽﮔﮋﯾﻭ

.ﺪﻧﺮﺑ ﯽﻣ ﺙﺭﺍ ﻪﺑ ﺍﺭ ﺩﻮﺧ ﻪﯿﻟﻭﺍ ﻪﻧﻮﻤﻧ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ءﺎﯿﺷﺍ

ﮏﯾ ﺎﻤﺷ ﺮﮔﺍ ﺎﻣﺍ ،ﺪﻨﮐ ﯽﻤﻧ ﻑﺬﺣ ﺍﺭ ﯽﺛﺭﺍ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﻑﺬﺣ<"code class="w3-codespan> ﯼﺪ

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