:ﺪﻫﺩ ﯼﺎﺟ ﺩﻮﺧ ﺭﺩ ﺍﺭ ﺭﺍﺪﻘﻣ ﮏﯾ ﺯﺍ ﺶﯿﺑ ﺪﻧﺍﻮﺗ ﯽﻣ ﻪﮐ ﺖﺳﺍ ﻩﮋﯾﻭ ﺮﯿﻐﺘﻣ ﮏﯾ ﻪﯾﺍﺭﺁ
const cars = ["Saab", "Volvo", "BMW"];
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p id="demo"></p>
<script>
const cars = ["Saab", "Volvo", "BMW"];
document.getElementById("demo").innerHTML = cars;
</script>
</body>
</html>
ﺪﯿﻨﮐ ﻩﺮﯿﺧﺫ ﺍﺭ ﻥﺁ ،(ﺎﻫﻭﺭﺩﻮﺧ ﻡﺎﻧ ﺯﺍ ﯽﺘﺳﺮﻬﻓ ﻼًﺜﻣ) ﺪﯾﺭﺍﺩ ﻡﻼﻗﺍ ﺯﺍ ﯽﺘﺳﺮﻬﻓ ﺮﮔﺍ
let car1 = "Saab";
let car2 = "Volvo";
let car3 = "BMW";
؟ﻪﭼ ،ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﺹﺎﺧ ﺩﺭﻮﻣ ﮏﯾ ﻭ ﺪﯿﻧﺰﺑ ﻪﻘﻠﺣ ﺍﺭ ﺎﻫﻦﯿﺷﺎﻣ ﺪﯿﻫﺍﻮﺨﺑ ﺮﮔﺍ ،ﻝﺎﺣ ﻦﯾﺍ ﺎﺑ
!ﺖﺳﺍ ﻪﯾﺍﺭﺁ ﮏﯾ ﻞﺣ ﻩﺍﺭ
ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ ﻭ ﺩﺭﺍﺩ ﻪﮕﻧ ﻡﺎﻧ ﮏﯾ ﺖﺤﺗ ﺍﺭ ﯼﺩﺎﯾﺯ ﺮﯾﺩﺎﻘﻣ ﺪﻧﺍﻮﺗ ﯽﻣ ﻪﯾﺍﺭﺁ ﮏﯾ
.ﺖﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ ﮏﯾ ﺩﺎﺠﯾﺍ ﯼﺍﺮﺑ ﻩﺍﺭ ﻦﯾﺮﺗ ﻩﺩﺎﺳ ﯽﻈﻔﻟ ﻪﯾﺍﺭﺁ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ
:ﻮﺤﻧ
const array_name = [item1, item2, ...];
.ﺪﯿﻨﮐ ﻡﻼﻋﺍ const ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺎﺑ ﺍﺭ ﺎﻫ ﻪﯾﺍﺭﺁ ﻪﮐ ﺖﺳﺍ ﻝﻮﻤﻌﻣ ﺵﻭﺭ ﮏﯾ ﻦﯾﺍ
.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ JS Array Const :ﻞﺼﻓ ﺭﺩ ﺎﻫﻪﯾﺍﺭﺁ ﺎﺑ const ﻩﺭﺎﺑﺭﺩ
const cars = ["Saab", "Volvo", "BMW"];
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p id="demo"></p>
<script>
const cars = ["Saab", "Volvo", "BMW"];
document.getElementById("demo").innerHTML = cars;
</script>
</body>
</html>
:ﺩﻮﺷ ﻞﻣﺎﺷ ﺍﺭ ﻂﺧ ﻦﯾﺪﻨﭼ ﺪﻧﺍﻮﺗ ﯽﻣ ﻥﻼﻋﺍ ﮏﯾ .ﺖﺴﯿﻧ ﻢﻬﻣ ﺖﺴﮑﺷ ﻁﻮﻄﺧ ﻭ ﺎﻫ ﻪﻠﺻﺎﻓ
const cars = [
"Saab",
"Volvo",
"BMW"
];
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p id="demo"></p>
<script>
const cars = [
"Saab",
"Volvo",
"BMW"
];
document.getElementById("demo").innerHTML = cars;
</script>
</body>
</html>
:ﺪﯿﻫﺩ ﻪﺋﺍﺭﺍ ﺍﺭ ﺮﺻﺎﻨﻋ ﺲﭙﺳ ﻭ ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ ﻪﯾﺍﺭﺁ ﮏﯾ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﻦﯿﻨﭽﻤﻫ ﺎﻤﺷ
const cars = [];
cars[0]= "Saab";
cars[1]= "Volvo";
cars[2]= "BMW";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p id="demo"></p>
<script>
const cars = [];
cars[0]= "Saab";
cars[1]= "Volvo";
cars[2]= "BMW";
document.getElementById("demo").innerHTML = cars;
</script>
</body>
</html>
:ﺪﻫﺩ ﯽﻣ ﺹﺎﺼﺘﺧﺍ ﻥﺁ ﻪﺑ ﺍﺭ ﯼﺮﯾﺩﺎﻘﻣ ﻭ ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﻪﯾﺍﺭﺁ ﮏﯾ ﻦﯿﻨﭽﻤﻫ ﺮﯾﺯ ﻝﺎﺜﻣ
const cars = new Array("Saab", "Volvo", "BMW");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p id="demo"></p>
<script>
const cars = new Array("Saab", "Volvo", "BMW");
document.getElementById("demo").innerHTML = cars;
</script>
</body>
</html>
.ﺪﻨﻨﮐ ﯽﻣ ﺍﺭ ﺭﺎﮐ ﻦﯿﻤﻫ ﺎًﻘﯿﻗﺩ ﻻﺎﺑ ﻝﺎﺜﻣ ﻭﺩ
.ﺖﺴﯿﻧ new Array()
ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻪﺑ ﯼﺯﺎﯿﻧ
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﯽﻈﻔﻟ ﻪﯾﺍﺭﺁ ﺵﻭﺭ ﺯﺍ ﺍﺮﺟﺍ ﺖﻋﺮﺳ ﻭ ﯽﯾﺎﻧﺍﻮﺧ ،ﯽﮔﺩﺎﺳ ﯼﺍﺮﺑ
:ﺪﯿﻨﮐ ﯽﻣ ﺍﺪﯿﭘ ﯽﺳﺮﺘﺳﺩ ﻪﯾﺍﺭﺁ ﺮﺼﻨﻋ ﮏﯾ ﻪﺑ ﺖﺳﺮﻬﻓ ﻩﺭﺎﻤﺷ ﻪﺑ ﻪﻌﺟﺍﺮﻣ ﺎﺑ ﺎﻤﺷ
const cars = ["Saab", "Volvo", "BMW"];
let car = cars[0];
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>Bracket Indexing</h2>
<p>JavaScript array elements are accessed using numeric indexes (starting from 0).</p>
<p id="demo"></p>
<script>
const cars = ["Saab", "Volvo", "BMW"];
document.getElementById("demo").innerHTML = cars[0];
</script>
</body>
</html>
ﻪﺟﻮﺗ: ﺺﺧﺎﺷﯽﻣ ﻉﻭﺮﺷ 0 ﺎﺑ ﻪﯾﺍﺭﺁ ﯼﺎﻫﺪﻧﻮﺷ.
.ﺖﺳﺍ ﺮﺼﻨﻋ ﻦﯿﻟﻭﺍ [0]
:ﺪﻫﺩ ﯽﻣ ﺮﯿﯿﻐﺗ cars
ﺭﺩ ﺍﺭ ﻝﻭﺍ ﺮﺼﻨﻋ ﺭﺍﺪﻘﻣ ﺕﺭﺎﺒﻋ ﻦﯾﺍ
cars[0] = "Opel";
const cars = ["Saab", "Volvo", "BMW"];
cars[0] = "Opel";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>Bracket Indexing</h2>
<p>JavaScript array elements are accessed using numeric indexes (starting from 0).</p>
<p id="demo"></p>
<script>
const cars = ["Saab", "Volvo", "BMW"];
cars[0] = "Opel";
document.getElementById("demo").innerHTML = cars;
</script>
</body>
</html>
ﺪﻨﮐ ﯽﻣ ﻞﯾﺪﺒﺗ ﻪﯾﺍﺭﺁ ﮏﯾ ﻪﺑ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ toString()
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺵﻭﺭ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits.toString();
:ﻪﺠﯿﺘﻧ
Banana,Orange,Apple,Mango→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The toString() Method</h2>
<p>The toString() method returns an array as a comma separated string:</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits.toString();
</script>
</body>
</html>
ﺖﺷﺍﺩ ﯽﺳﺮﺘﺳﺩ ﻞﻣﺎﮐ ﻪﯾﺍﺭﺁ ﻪﺑ ﻥﺍﻮﺗ ﯽﻣ ﻪﯾﺍﺭﺁ ﻪﺑ ﻪﻌﺟﺍﺮﻣ ﺎﺑ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺎﺑ
const cars = ["Saab", "Volvo", "BMW"];
document.getElementById("demo").innerHTML = cars;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p id="demo"></p>
<script>
const cars = ["Saab", "Volvo", "BMW"];
document.getElementById("demo").innerHTML = cars;
</script>
</body>
</html>
ﯼﺍﺮﺑ ﺍﺭ "object" ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ typeof
ﺮﮕﻠﻤﻋ .ﺪﻨﺘﺴﻫ ﺎﯿﺷﺍ ﺯﺍ ﯽﺻﺎﺧ ﻉﻮﻧ ﺎﻫ ﻪﯾﺍﺭﺁ
.ﺪﻧﻮﺷ ﯽﻣ ﻒﯿﺻﻮﺗ ﻪﯾﺍﺭﺁ ﻥﺍﻮﻨﻋ ﻪﺑ ﻪﺟﻭ ﻦﯾﺮﺘﻬﺑ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻪﯾﺍﺭﺁ ﺎﻣﺍ
ﻦﯾﺍ ﺭﺩ .ﺪﻨﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺩﻮﺧ "ﺮﺻﺎﻨﻋ" ﻪﺑ ﯽﺳﺮﺘﺳﺩ ﯼﺍﺮﺑ ﺩﺍﺪﻋﺍ ﺯﺍ ﺎﻫ ﻪﯾﺍﺭﺁ
const person = ["John", "Doe", 46];
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Arrays</h2>
<p>Arrays use numbers to access its elements.</p>
<p id="demo"></p>
<script>
const person = ["John", "Doe", 46];
document.getElementById("demo").innerHTML = person[0];
</script>
</body>
</html>
،ﻝﺎﺜﻣ ﻦﯾﺍ ﺭﺩ .ﺪﻨﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺩﻮﺧ "ﯼﺎﻀﻋﺍ" ﻪﺑ ﯽﺳﺮﺘﺳﺩ ﯼﺍﺮﺑ ﻡﺎﻧ ﺯﺍ ﺎﯿﺷﺍ
const person = {firstName:"John", lastName:"Doe", age:46};
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Objects</h1>
<p>JavaScript uses names to access object properties.</p>
<p id="demo"></p>
<script>
const person = {firstName:"John", lastName:"Doe", age:46};
document.getElementById("demo").innerHTML = person.firstName;
</script>
</body>
</html>
.ﺪﻨﺘﺴﻫ ءﺎﯿﺷﺍ ﺯﺍ ﯽﺻﺎﺧ ﻉﺍﻮﻧﺍ ﺎﻫ ﻪﯾﺍﺭﺁ .ﺪﻨﺷﺎﺑ ﺎﯿﺷﺍ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫﺮﯿﻐﺘﻣ
ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻥﺁ ﺭﺩ ﻒﻠﺘﺨﻣ ﻉﺍﻮﻧﺍ ﺯﺍ ﯽﯾﺎﻫﺮﯿﻐﺘﻣ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ ،ﻞﯿﻟﺩ ﻦﯿﻤﻫ ﻪﺑ
ﯽﻧﺍﻮﺗ ﯽﻣ ﻮﺗ .ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﯾﺍﺭﺁ ﮏﯾ ﺭﺩ ﯽﻌﺑﺍﻮﺗ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ .ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﯾﺍﺭﺁ ﮏﯾ ﺭﺩ ﺍﺭ ءﺎﯿﺷﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ
myArray[0] = Date.now;
myArray[1] = myFunction;
myArray[2] = myCars;
ﻭ ﯽﻠﺧﺍﺩ ﻪﯾﺍﺭﺁ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻪﯾﺍﺭﺁ ﯽﻌﻗﺍﻭ ﺕﺭﺪﻗ
cars.length // Returns the number of elements
cars.sort() // Sorts the array
.ﺖﺳﺍ ﻩﺪﺷ ﻩﺩﺍﺩ ﺶﺷﻮﭘ ﯼﺪﻌﺑ ﯼﺎﻫ ﻞﺼﻓ ﺭﺩ ﻪﯾﺍﺭﺁ ﯼﺎﻫ ﺵﻭﺭ
.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ (ﻪﯾﺍﺭﺁ ﺩﺍﺪﻌﺗ) ﻪﯾﺍﺭﺁ ﮏﯾ ﻝﻮﻃ ﻪﯾﺍﺭﺁ ﮏﯾ length
ﯽﮔﮋﯾﻭ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let length = fruits.length;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The length Property</h2>
<p>The length property returns the length of an array:</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let size = fruits.length;
document.getElementById("demo").innerHTML = size;
</script>
</body>
</html>
.ﺖﺳﺍ ﻪﯾﺍﺭﺁ ﺺﺧﺎﺷ ﻦﯾﺮﺗﻻﺎﺑ ﺯﺍ ﺮﺘﺸﯿﺑ ﮏﯾ ﻪﺸﯿﻤﻫ length
ﯽﮔﮋﯾﻭ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let fruit = fruits[0];
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>Bracket Indexing</h2>
<p>JavaScript array elements are accesses using numeric indexes (starting from 0).</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits[0];
</script>
</body>
</html>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let fruit = fruits[fruits.length - 1];
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>Bracket Indexing</h2>
<p>JavaScript array elements are accesses using numeric indexes (starting from 0).</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits[fruits.length-1];
</script>
</body>
</html>
:ﺖﺳﺍ for
ﻪﻘﻠﺣ ﮏﯾ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ،ﻪﯾﺍﺭﺁ ﮏﯾ ﻖﯾﺮﻃ ﺯﺍ ﻥﺩﺯ ﻪﻘﻠﺣ ﯼﺎﻫ ﻩﺍﺭ ﺯﺍ ﯽﮑﯾ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let fLen = fruits.length;
let text = "<ul>";
for (let i = 0; i < fLen; i++) {
text += "<li>" + fruits[i] + "</li>";
}
text
+= "</ul>";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>Looping an Array</h2>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let fLen = fruits.length;
let text = "<ul>";
for (let i = 0; i < fLen; i++) {
text += "<li>" + fruits[i] + "</li>";
}
text += "</ul>";
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ Array.forEach()
ﻊﺑﺎﺗ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﻦﯿﻨﭽﻤﻫ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let text = "<ul>";
fruits.forEach(myFunction);
text += "</ul>";
function
myFunction(value) {
text += "<li>" + value + "</li>";
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The forEach() Method</h2>
<p>Call a function for each array element:</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let text = "<ul>";
fruits.forEach(myFunction);
text += "</ul>";
document.getElementById("demo").innerHTML = text;
function myFunction(value) {
text += "<li>" + value + "</li>";
}
</script>
</body>
</html>
:ﺖﺳﺍ push()
ﺵﻭﺭ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻪﯾﺍﺭﺁ ﻪﺑ ﺪﯾﺪﺟ ﺮﺼﻨﻋ ﮏﯾ ﻥﺩﻭﺰﻓﺍ ﯼﺍﺮﺑ ﻩﺍﺭ ﻦﯾﺮﺗ ﻩﺩﺎﺳ
const fruits = ["Banana", "Orange", "Apple"];
fruits.push("Lemon"); // Adds a new element (Lemon) to fruits
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The push() Method</h2>
<p>The push method appends a new element to an array.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple"];
document.getElementById("demo").innerHTML = fruits;
function myFunction() {
fruits.push("Lemon");
document.getElementById("demo").innerHTML = fruits;
}
</script>
</body>
</html>
:ﺩﺮﮐ ﻪﻓﺎﺿﺍ ﻪﯾﺍﺭﺁ ﻪﺑ ﺍﺭ ﺪﯾﺪﺟ ﺮﺼﻨﻋ ،length
ﯽﮔﮋﯾﻭ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﻥﺍﻮﺗ ﯽﻣ ﻦﯿﻨﭽﻤﻫ
const fruits = ["Banana", "Orange", "Apple"];
fruits[fruits.length] = "Lemon"; // Adds "Lemon" to fruits
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p>The length property provides an easy way to append new elements to an array without using the push() method.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple"];
document.getElementById("demo").innerHTML = fruits;
function myFunction() {
fruits[fruits.length] = "Lemon";
document.getElementById("demo").innerHTML = fruits;
}
</script>
</body>
</html>
ﺭﺍﺪﺸﻫ!
const fruits = ["Banana", "Orange", "Apple"];
fruits[6] = "Lemon"; // Creates undefined "holes" in fruits
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p>Adding elements with high indexes can create undefined "holes" in an array.</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple"];
fruits[6] = "Lemon";
let fLen = fruits.length;
let text = "";
for (i = 0; i < fLen; i++) {
text += fruits[i] + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
.ﺪﻨﻨﮐ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻩﺪﺷ ﯼﺭﺍﺬﮕﻣﺎﻧ ﯼﺎﻫ ﻪﯾﺎﻤﻧ ﺎﺑ ﯽﯾﺎﻫ ﻪﯾﺍﺭﺁ ﺯﺍ ﯽﺴﯾﻮﻧ ﻪﻣﺎﻧﺮﺑ ﯼﺎﻫ ﻥﺎﺑﺯ ﺯﺍ ﯼﺭﺎﯿﺴﺑ
ﺪﻧﻮﺷ ﯽﻣ ﻩﺪﯿﻣﺎﻧ ﯽﻨﻤﺠﻧﺍ ﺪﻧﺭﺍﺩ ﻩﺪﺷ ﯼﺭﺍﺬﮕﻣﺎﻧ ﯼﺎﻫ ﺺﺧﺎﺷ ﻪﮐ ﯽﯾﺎﻫ ﻪﯾﺍﺭﺁ
.ﺪﻨﮐ ﯽﻤﻧ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥ ﻩﺪﺷ ﯼﺭﺍﺬﮕﻣﺎﻧ ﯼﺎﻫ ﻪﯾﺎﻤﻧ ﯼﺍﺭﺍﺩ ﯼﺎﻫ ﻪﯾﺍﺭﺁ ﺯﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
.ﺪﻨﻨﮐﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺭﺍﺩﻩﺭﺎﻤﺷ ﯼﺎﻫﺺﺧﺎﺷ ﺯﺍ ﻪﺸﯿﻤﻫ ﺎﻫﻪﯾﺍﺭﺁ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
const person = [];
person[0] = "John";
person[1] = "Doe";
person[2] = 46;
person.length; // Will return 3
person[0]; // Will return "John"
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p id="demo"></p>
<script>
const person = [];
person[0] = "John";
person[1] = "Doe";
person[2] = 46;
document.getElementById("demo").innerHTML =
person[0] + " " + person.length;
</script>
</body>
</html>
ﺭﺍﺪﺸﻫ!!
ﺪﻨﻨﮐ ﯽﻣ ﺪﯿﻟﻮﺗ ﺖﺳﺭﺩﺎﻧ ﻪﯾﺍﺭﺁ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﻭ ﺎﻫ ﺵﻭﺭ ﺯﺍ ﯽﺧﺮﺑ ،ﻥﺁ ﺯﺍ ﺲﭘ
const person = [];
person["firstName"] = "John";
person["lastName"] = "Doe";
person["age"] = 46;
person.length; // Will return 0
person[0]; // Will return undefined
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p>If you use a named index when accessing an array, JavaScript will redefine the array to a standard object, and some array methods and properties will produce undefined or incorrect results.</p>
<p id="demo"></p>
<script>
const person = [];
person["firstName"] = "John";
person["lastName"] = "Doe";
person["age"] = 46;
document.getElementById("demo").innerHTML =
person[0] + " " + person.length;
</script>
</body>
</html>
.ﺪﻨﻨﮐﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺭﺍﺩﻩﺭﺎﻤﺷ ﯼﺎﻫﺺﺧﺎﺷ ﺯﺍ ﺎﻫﻪﯾﺍﺭﺁ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ
.ﺪﻨﻨﮐﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻩﺪﺷ ﯼﺭﺍﺬﮔﻡﺎﻧ ﯼﺎﻫﺺﺧﺎﺷ ﺯﺍ ءﺎﯿﺷﺍ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ
.ﺪﻧﺭﺍﺩ ﻩﺪﺷ ﯼﺭﺍﺬﮔ ﻩﺭﺎﻤﺷ ﯼﺎﻫ ﺺﺧﺎﺷ ﻪﮐ ﺪﻨﺘﺴﻫ ءﺎﯿﺷﺍ ﺯﺍ ﯽﺻﺎﺧ ﻉﻮﻧ ﺎﻫ ﻪﯾﺍﺭﺁ
.ﺪﻨﮐ ﯽﻤﻧ ﯽﻧﺎﺒﯿﺘﺸﭘ ﯽﻨﻤﺠﻧﺍ ﯼﺎﻫ ﻪﯾﺍﺭﺁ ﺯﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ءﺎﯿﺷﺍ ﺯﺍ ﺪﯾﺎﺑ ،ﺪﺷﺎﺑ ﺮﺻﺎﻨﻋ ﻡﺎﻧ ﺪﯿﻫﺍﻮﺧﯽﻣ ﯽﺘﻗﻭ
ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺎﻫﻪﯾﺍﺭﺁ ﺯﺍ ﺪﯾﺎﺑ ،ﺪﺷﺎﺑ ﺮﺻﺎﻨﻋ ﻡﺎﻧ ﺪﯿﻫﺍﻮﺧﯽﻣ ﯽﺘﻗﻭ
.ﺖﺳﺍ ﺪﯾﺪﺟ () ﻪﯾﺍﺭﺁ<"code class="w3-codespan> ﯽﻠﺧﺍﺩ ﻪﯾﺍﺭﺁ ﻩﺪﻧﺯﺎﺳ ﮏﯾ ﯼﺍﺭﺍﺩ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ []
ﺯﺍ ﺖﺣﺍﺭ ﻝﺎﯿﺧ ﺎﺑ ﺪﯿﻧﺍﻮﺗﯽﻣ ﺎﻣﺍ
:ﺪﻨﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﻁﺎﻘﻧ ﻡﺎﻧ ﻪﺑ ﺪﯾﺪﺟ ﯽﻟﺎﺧ ﻪﯾﺍﺭﺁ ﮏﯾ ﻭﺩ ﺮﻫ ﻒﻠﺘﺨﻣ ﺕﺭﺎﺒﻋ ﻭﺩ ﻦﯾﺍ
const points = new Array();
const points = [];
:ﺪﻨﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺩﺪﻋ 6 ﯼﻭﺎﺣ ﺪﯾﺪﺟ ﻪﯾﺍﺭﺁ ﮏﯾ ﻭﺩ ﺮﻫ ﻒﻠﺘﺨﻣ ﺕﺭﺎﺒﻋ ﻭﺩ ﻦﯾﺍ
const points = new Array(40, 100, 1, 5, 25, 10);
const points = [40, 100, 1, 5, 25, 10];
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>Creating an Array</h2>
<p>Avoid using new Array(). Use [] instead.</p>
<p id="demo"></p>
<script>
//const points = new Array(40, 100, 1, 5, 25, 10);
const points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = points[0];
</script>
</body>
</html>
:ﺪﻨﮐ ﺩﺎﺠﯾﺍ ﯼﺍ ﻩﺮﻈﺘﻨﻣﺮﯿﻏ ﺞﯾﺎﺘﻧ ﺪﻧﺍﻮﺗ ﯽﻣ new
ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ
// Create an array with three elements:
const points = new Array(40, 100, 1);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Arrays</h2>
<p>Create an Array with three elements.</p>
<p id="demo"></p>
<script>
var points = new Array(40, 100, 1);
document.getElementById("demo").innerHTML = points;
</script>
</body>
</html>
// Create an array with two elements:
const points = new Array(40, 100);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Arrays</h2>
<p>Create an Array with two elements.</p>
<p id="demo"></p>
<script>
var points = new Array(40, 100);
document.getElementById("demo").innerHTML = points;
</script>
</body>
</html>
// Create an array with one element ???
const points = new Array(40);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p>Avoid using new Array().</p>
<p id="demo"></p>
<script>
var points = new Array(40);
document.getElementById("demo").innerHTML = points;
</script>
</body>
</html>
const points = [40];
:ﺖﺴﯿﻧ ﻥﺎﺴﮑﯾ
const points = new Array(40);
// Create an array with one element:
const points = [40];
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p>Create an Array with one element.</p>
<p id="demo"></p>
<script>
var points = [40];
document.getElementById("demo").innerHTML = points;
</script>
</body>
</html>
// Create an array with 40 undefined elements:
const points = new Array(40);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p>Avoid using new Array().</p>
<p id="demo"></p>
<script>
var points = new Array(40);
document.getElementById("demo").innerHTML = points[0];
</script>
</body>
</html>
؟ﺖﺳﺍ ﻪﯾﺍﺭﺁ ﺮﯿﻐﺘﻣ ﮏﯾ ﻪﮐ ﻢﻤﻬﻔﺑ ﻪﻧﻮﮕﭼ :ﺖﺳﺍ ﻦﯾﺍ ﺞﯾﺍﺭ ﻝﺍﻮﺳ ﮏﯾ
ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ typeof
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺮﮕﻠﻤﻋ ﻪﮐ ﺖﺳﺍ ﻦﯾﺍ ﻞﮑﺸﻣ
const fruits = ["Banana", "Orange", "Apple"];
let type = typeof fruits;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The typeof Operator</h2>
<p>The typeof operator, when used on an array, returns object:</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = typeof fruits;
</script>
</body>
</html>
ﺖﺳﺍ an ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ ﮏﯾ ﺍﺮﯾﺯ ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﯽﺷ typeof ﺮﮕﻠﻤﻋ
:Array.isArray()
ﺩﺮﮐ ﻒﯾﺮﻌﺗ ﺍﺭ ﯼﺪﯾﺪﺟ ﺵﻭﺭ (2009 ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ) ECMAScript 5 ﻞﮑﺸﻣ ﻦﯾﺍ ﻞﺣ
Array.isArray(fruits);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The isArray() Method</h2>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple"];
document.getElementById("demo").innerHTML = Array.isArray(fruits);
</script>
</body>
</html>
.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ true ﺭﺍﺪﻘﻣ ،ءﯽﺷ ﮏﯾ ﺩﺎﺠﯾﺍ ﺕﺭﻮﺻ ﺭﺩ ﻪﻧﻮﻤﻧ<"code class="w3-codespan> ﺮﮕﻠﻤﻋ
const fruits = ["Banana", "Orange", "Apple"];
fruits instanceof Array;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The instanceof Operator</h2>
<p>The instanceof operator returns true when used on an array:</p>
<p id="demo"></p>
<script>
var fruits = ["Banana", "Orange", "Apple"];
document.getElementById("demo").innerHTML = fruits instanceof Array;
</script>
</body>
</html>
:ﺪﯾﻭﺮﺑ ﺎﻣ ﺱﺭﺩﺁ ﻪﺑ ،ﻪﯾﺍﺭﺁ ﻞﻣﺎﮐ ﻊﺟﺮﻣ ﮏﯾ ﯼﺍﺮﺑ
.ﻞﻣﺎﮐ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ ﻊﺟﺮﻣ
ﺖﺳﺍ ﺎﻫ ﻪﯾﺍﺭﺁ ﻪﻤﻫ ﺯﺍ ﯽﯾﺎﻫ ﻪﻧﻮﻤﻧ ﻭ ﺕﺎﺤﯿﺿﻮﺗ ﯼﻭﺎﺣ ﻊﺟﺮﻣ