ﺪﻧﺍ ﻩﺪﺷ ﺖﺳﺮﻬﻓ ﺪﻧﻮﺷ ﯽﻣ ﺮﻫﺎﻇ ﺵﺯﻮﻣﺁ ﻪﺤﻔﺻ ﻦﯾﺍ ﺭﺩ ﻪﮐ ﯽﺒﯿﺗﺮﺗ ﻪﺑ ﺎﻫﺪﺘﻣ
Array length Array toString() Array pop() Array push() Array shift() Array unshift() Array join() Array delete() Array concat() Array flat() Array splice() Array slice()
:ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ (ﻩﺯﺍﺪﻧﺍ) ﻝﻮﻃ length
ﯽﮔﮋﯾﻭ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let size = 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>
toString()
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ ﺪﻨﮐ ﯽﻣ ﻞﯾﺪﺒﺗ ﻪﯾﺍﺭﺁ ﮏﯾ ﻪﺑ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ 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>
.ﺩﺪﻧﻮﯿﭘ ﯽﻣ ﻪﺘﺷﺭ ﮏﯾ ﻪﺑ ﺍﺭ ﻪﯾﺍﺭﺁ ﺮﺻﺎﻨﻋ ﻪﻤﻫ ﺰﯿﻧ join()
ﺪﺘﻣ
:ﺪﯿﻨﮐ ﺺﺨﺸﻣ ﺍﺭ ﻩﺪﻨﻨﮐﺍﺪﺟ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﻦﯾﺍ ﺮﺑ ﻩﻭﻼﻋ ﺎﻣﺍ ،ﺪﻨﮐ ﯽﻣ ﻞﻤﻋ toString()
ﺪﻨﻧﺎﻣ ﺖﺳﺭﺩ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits.join(" * ");
:ﻪﺠﯿﺘﻧ
Banana * Orange * Apple * Mango→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The join() Method</h2>
<p>The join() method joins array elements into a string.</p>
<p>It this example we have used " * " as a separator between the elements:</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits.join(" * ");
</script>
</body>
</html>
ﺖﺳﺍ ﻥﺎﺳﺁ ﻥﺩﺮﮐ ﻪﻓﺎﺿﺍ ﻭ ﺮﺻﺎﻨﻋ ﻑﺬﺣ ،ﺪﯿﻨﮐ ﯽﻣ ﺭﺎﮐ ﺎﻫ ﻪﯾﺍﺭﺁ ﺎﺑ ﯽﺘﻗﻭ
:ﻪﻨﯾﺍ ﻥﺩﺍﺩ ﻞﻫ ﻭ ﻥﺩﺯ ﭖﺎﭘ
ﻥﺩﺍﺩ ﺭﺎﺸﻓ ﺎﯾ ،ﻪﯾﺍﺭﺁ ﺯﺍ ﻥﻭﺮﯿﺑ ﺩﺭﺍﻮﻣ ﻥﺪﻣﺁ ﻥﻭﺮﯿﺑ
pop()
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ :ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﻪﯾﺍﺭﺁ ﺯﺍ ﺍﺭ ﺮﺼﻨﻋ ﻦﯾﺮﺧﺁ pop()
ﺪﺘﻣ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.pop();
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The pop() Method</h2>
<p>The pop() method removes the last element from an array.</p>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = fruits;
fruits.pop();
document.getElementById("demo2").innerHTML = fruits;
</script>
</body>
</html>
:ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺩﻮﺑ "popped out" ﻪﮐ ﺍﺭ ﯼﺭﺍﺪﻘﻣ pop()
ﺵﻭﺭ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let fruit = fruits.pop();
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The pop() Method</h2>
<p>The pop() method returns the value that was "popped out":</p>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = fruits.pop();
document.getElementById("demo2").innerHTML = fruits;
</script>
</body>
</html>
push()
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ :(ﻥﺎﯾﺎﭘ ﺭﺩ) ﺪﻨﮐ ﯽﻣ ﻪﻓﺎﺿﺍ ﻪﯾﺍﺭﺁ ﻪﺑ ﺪﯾﺪﺟ ﺮﺼﻨﻋ ﮏﯾ push()
ﺵﻭﺭ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!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>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = fruits;
fruits.push("Kiwi");
document.getElementById("demo2").innerHTML = fruits;
</script>
</body>
</html>
:ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ ﺪﯾﺪﺟ ﻪﯾﺍﺭﺁ ﻝﻮﻃ push()
ﺵﻭﺭ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let length = fruits.push("Kiwi");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The push() Method</h2>
<p>The push() method returns the new array length:</p>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = fruits.push("Kiwi");
document.getElementById("demo2").innerHTML = fruits;
</script>
</body>
</html>
ﺪﯿﻨﮐ ﺭﺎﮐ ﻝﻭﺍ ﺮﺼﻨﻋ ﯼﻭﺭ ﺭﺎﮐ ﯼﺎﺟ ﻪﺑ ﺎﻣﺍ ،ﺖﺳﺍ ﻥﺩﺮﮐ ﭖﺎﭘ ﻝﺩﺎﻌﻣ ﯽﯾﺎﺠﺑﺎﺟ
shift()
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ .ﺪﻨﮐ ﯽﻣ "shift" ﺍﺭ ﻪﻤﻫ ﻭ ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﺍﺭ ﻪﯾﺍﺭﺁ ﺮﺼﻨﻋ ﻦﯿﻟﻭﺍ shift()
ﺵﻭﺭ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift();
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The shift() Method</h2>
<p>The shift() method removes the first element of an array (and "shifts" the other elements to the left):</p>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = fruits;
fruits.shift();
document.getElementById("demo2").innerHTML = fruits;
</script>
</body>
</html>
:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺩﻮﺑ ﻩﺪﺷ "shifted out" ﻪﮐ ﺍﺭ ﯼﺭﺍﺪﻘﻣ shift()
ﺵﻭﺭ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let fruit = fruits.shift();
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The shift() Method</h2>
<p>The shift() method returns the element that was shifted out.</p>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = fruits.shift();
document.getElementById("demo2").innerHTML = fruits;
</script>
</body>
</html>
unshift()
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ .ﺪﻨﮐ ﯽﻣ "unshift" ﻭ ﺪﻨﮐ ﯽﻣ ﻪﻓﺎﺿﺍ (ﺍﺪﺘﺑﺍ ﺭﺩ) ﻪﯾﺍﺭﺁ ﻪﺑ ﺪﯾﺪﺟ ﺮﺼﻨﻋ ﮏﯾ unshift()
ﺪﺘﻣ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Lemon");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The unshift() Method</h2>
<p>The unshift() method adds new elements to the beginning of an array:</p>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = fruits;
fruits.unshift("Lemon");
document.getElementById("demo2").innerHTML = fruits;
</script>
</body>
</html>
:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﺪﯾﺪﺟ ﻪﯾﺍﺭﺁ ﻝﻮﻃ unshift()
ﺵﻭﺭ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Lemon");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The unshift() Method</h2>
<p>The unshift() method returns the length of the new array:</p>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = fruits.unshift("Lemon");
document.getElementById("demo2").innerHTML = fruits;
</script>
</body>
</html>
:ﺪﻨﺘﺴﻫ ﯽﺳﺮﺘﺳﺩ ﻞﺑﺎﻗ ﺎﻬﻧﺁ ﺖﺳﺮﻬﻓ ﻩﺭﺎﻤﺷ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﻪﯾﺍﺭﺁ ﺮﺻﺎﻨﻋ
:ﺩﻮﺷ ﯽﻣ ﻉﻭﺮﺷ 0 ﺎﺑ ﺺﺧﺎﺷ ﻪﯾﺍﺭﺁ
... ﺮﺼﻨﻋ ﻦﯿﻣﻮﺳ br>[2]>ﺖﺳﺍ ﺮﺼﻨﻋ ﻦﯿﻣﻭﺩ br>[1]>ﺖﺳﺍ ﻪﯾﺍﺭﺁ ﺮﺼﻨﻋ ﻦﯿﻟﻭﺍ [0]
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits[0] = "Kiwi";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>Bracket Indexing</h2>
<p>Array elements are accessed using their index number:</p>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = fruits;
fruits[0] = "Kiwi";
document.getElementById("demo2").innerHTML = fruits;
</script>
</body>
</html>
:ﺪﻫﺩ ﯽﻣ ﻪﺋﺍﺭﺍ ﻪﯾﺍﺭﺁ ﻪﺑ ﺪﯾﺪﺟ ﺮﺼﻨﻋ ﮏﯾ ﻕﺎﺤﻟﺍ ﯼﺍﺮﺑ ﺍﺭ ﯽﻧﺎﺳﺁ ﻩﺍﺭ length
ﯽﮔﮋﯾﻭ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits[fruits.length] = "Kiwi";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The length Property</h2>
<p>The length property provides an easy way to append new elements to an array without using the push() method:</p>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = fruits;
fruits[fruits.length] = "Kiwi";
document.getElementById("demo2").innerHTML = fruits;
</script>
</body>
</html>
delete()
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ .ﺩﺮﮐ ﻑﺬﺣ ﻑﺬﺣ<"code class="w3-codespan> ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺮﮕﻠﻤﻋ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﻪﯾﺍﺭﺁ ﺮﺻﺎﻨﻋ
ﺭﺩ ﺍﺭ ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ<"code class="w3-codespan> ﯼﺎﻫﻩﺮﻔﺣ
ﻑﺬﺣ<"code class="w3-codespan> ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ()shift ﺎﯾ()pop ﺯﺍ ﻥﺁ ﯼﺎﺟ ﻪﺑ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
delete fruits[0];
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The delete Method</h2>
<p>Deleting elements leaves undefined holes in an array:</p>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML =
"The first fruit is: " + fruits[0];
delete fruits[0];
document.getElementById("demo2").innerHTML =
"The first fruit is: " + fruits[0];
</script>
</body>
</html>
.ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﯼﺪﯾﺪﺟ ﻪﯾﺍﺭﺁ (ﻕﺎﺤﻟﺍ) ﻡﺎﻏﺩﺍ ﺎﺑ concat()
ﺪﺘﻣ
const myGirls = ["Cecilie", "Lone"];
const myBoys = ["Emil", "Tobias", "Linus"];
const myChildren = myGirls.concat(myBoys);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The concat() Method</h2>
<p>The concat() method merges (concatenates) arrays:</p>
<p id="demo"></p>
<script>
const myGirls = ["Cecilie", "Lone"];
const myBoys = ["Emil", "Tobias", "Linus"];
const myChildren = myGirls.concat(myBoys);
document.getElementById("demo").innerHTML = myChildren;
</script>
</body>
</html>
.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺪﯾﺪﺟ ﻪﯾﺍﺭﺁ ﮏﯾ ﻪﺸﯿﻤﻫ .ﺪﻫﺩ ﯽﻤﻧ ﺮﯿﯿﻐﺗ ﺍﺭ ﺩﻮﺟﻮﻣ ﯼﺎﻫ ﻪﯾﺍﺭﺁ concat()
ﺵﻭﺭ
:ﺩﺮﯿﮕﺑ ﺍﺭ ﻪﯾﺍﺭﺁ ﻥﺎﻣﻮﮔﺭﺁ ﺩﺍﺪﻌﺗ ﺮﻫ ﺪﻧﺍﻮﺗﯽﻣ concat()
ﺪﺘﻣ
const arr1 = ["Cecilie", "Lone"];
const arr2 = ["Emil", "Tobias", "Linus"];
const arr3 = ["Robin", "Morgan"];
const myChildren = arr1.concat(arr2, arr3);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The concat() Method</h2>
<p>The concat() method merges (concatenates) arrays:</p>
<p id="demo"></p>
<script>
const array1 = ["Cecilie", "Lone"];
const array2 = ["Emil", "Tobias", "Linus"];
const array3 = ["Robin", "Morgan"];
const myChildren = array1.concat(array2, array3);
document.getElementById("demo").innerHTML = myChildren;
</script>
</body>
</html>
:ﺩﺮﯿﮕﺑ ﻥﺎﻣﻮﮔﺭﺁ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﯽﯾﺎﻫﻪﺘﺷﺭ ﺪﻧﺍﻮﺗﯽﻣ ﻦﯿﻨﭽﻤﻫ concat()
ﺪﺘﻣ
const arr1 = ["Emil", "Tobias", "Linus"];
const myChildren = arr1.concat("Peter");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The concat() Method</h2>
<p>The concat() method can merge string values to arrays:</p>
<p id="demo"></p>
<script>
const myArray = ["Emil", "Tobias", "Linus"];
const myChildren = myArray.concat("Peter");
document.getElementById("demo").innerHTML = myChildren;
</script>
</body>
</html>
.ﺖﺳﺍ ﻪﯾﺍﺭﺁ ﮏﯾ ﺩﺎﻌﺑﺍ ﺶﻫﺎﮐ ﺪﻨﯾﺁﺮﻓ ﻪﯾﺍﺭﺁ ﮏﯾ ﻥﺩﺮﮐ ﺢﻄﺴﻣ
.ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﯽﺼﺨﺸﻣ ﻖﻤﻋ ﻪﺑ ﻪﺘﺳﻮﯿﭘ ﻢﻫ ﻪﺑ ﻪﯾﺍﺭﺁ ﺮﯾﺯ ﺮﺻﺎﻨﻋ ﺎﺑ ﺪﯾﺪﺟ ﻪﯾﺍﺭﺁ ﮏﯾ()flat ﺪﺘﻣ
const myArr = [[1,2],[3,4],[5,6]];
const newArr = myArr.flat();
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The flat() Method</h2>
<p id="demo"></p>
<script>
const myArr = [[1,2],[3,4],[5,6]];
const newArr = myArr.flat();
document.getElementById("demo").innerHTML = newArr;
</script>
</body>
</html>
JavaScript Array flat()
ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﻤﻫ ﺭﺩ 2020 ﻪﯾﻮﻧﺍﮊ ﺯﺍﺩﻮﺷ:
Chrome 69 | Edge 79 | Firefox 62 | Safari 12 | Opera 56 |
Sep 2018 | Jan 2020 | Sep 2018 | Sep 2018 | Sep 2018 |
.ﺪﻨﮐ ﯽﻣ ﻪﻓﺎﺿﺍ ﻪﯾﺍﺭﺁ ﮏﯾ ﻪﺑ ﺍﺭ ﯼﺪﯾﺪﺟ ﺩﺭﺍﻮﻣ splice()
ﺵﻭﺭ
.ﺪﻫﺩ ﯽﻣ ﺵﺮﺑ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ ﺯﺍ ﻪﻌﻄﻗ ﮏﯾ slice()
ﺵﻭﺭ
splice()
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ :ﺩﻮﺷ ﻩﺩﺎﻔﺘﺳﺍ ﻪﯾﺍﺭﺁ ﻪﺑ ﺪﯾﺪﺟ ﯼﺎﻫ ﻢﺘﯾﺁ ﻥﺩﻭﺰﻓﺍ ﯼﺍﺮﺑ ﺪﻧﺍﻮﺗ ﯽﻣ splice()
ﺵﻭﺭ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 0, "Lemon", "Kiwi");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The splice() Method</h2>
<p>The splice() method adds new elements to an array:</p>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = fruits;
fruits.splice(2, 0, "Lemon", "Kiwi");
document.getElementById("demo2").innerHTML = fruits;
</script>
</body>
</html>
ﺪﻨﮐ ﯽﻣ ﺺﺨﺸﻣ ﺍﺭ ﺪﯾﺪﺟ ﺮﺻﺎﻨﻋ ﯽﯾﺎﺟ ﺖﯿﻌﻗﻮﻣ (2) ﺮﺘﻣﺍﺭﺎﭘ ﻦﯿﻟﻭﺍ
ﺪﻨﮐ ﯽﻣ ﺺﺨﺸﻣ ﺍﺭ ﺮﺼﻨﻋ ﺪﻨﭼ (0) ﻡﻭﺩ ﺮﺘﻣﺍﺭﺎﭘ
ﺪﻨﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ ﺍﺭ ﺪﯾﺪﺟ ﺮﺻﺎﻨﻋ ("ﯼﻮﯿﮐ" ،"ﻮﻤﯿﻟ") ﺎﻫﺮﺘﻣﺍﺭﺎﭘ ﻪﯿﻘﺑ
:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻩﺪﺷ ﻑﺬﺣ ﺩﺭﺍﻮﻣ ﺎﺑ ﺍﺭ ﯼﺍ ﻪﯾﺍﺭﺁ splice()
ﺵﻭﺭ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 2, "Lemon", "Kiwi");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The splice() Method</h2>
<p>The splice() method adds new elements to an array, and returns an array with the deleted elements (if any):</p>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = "Original Array:<br> " + fruits;
let removed = fruits.splice(2, 2, "Lemon", "Kiwi");
document.getElementById("demo2").innerHTML = "New Array:<br>" + fruits;
document.getElementById("demo3").innerHTML = "Removed Items:<br> " + removed;
</script>
</body>
</html>
splice()
ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺝﻭﺮﺧ ﻥﻭﺪﺑ ﺮﺻﺎﻨﻋ ﻑﺬﺣ ﯼﺍﺮﺑ splice()
ﺯﺍ ﺪﯿﻧﺍﻮﺗﯽﻣ ،ﺮﺘﻣﺍﺭﺎﭘ ﻪﻧﺍﺪﻨﻤﺷﻮﻫ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(0, 1);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The splice() Method</h2>
<p>The splice() methods can be used to remove array elements:</p>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = fruits;
fruits.splice(0, 1);
document.getElementById("demo2").innerHTML = fruits;
</script>
</body>
</html>
ﺪﻨﮐ ﯽﻣ ﺺﺨﺸﻣ ﺍﺭ ﺪﻧﺮﯿﮔ ﺭﺍﺮﻗ ﻥﺁ ﺭﺩ ﺪﯾﺎﺑ ﺪﯾﺪﺟ ﺮﺻﺎﻨﻋ ﻪﮐ ﺍﺭ ﯽﺘﯿﻌﻗﻮﻣ (0) ﻝﻭﺍ ﺮﺘﻣﺍﺭﺎﭘ
ﺪﻨﮐ ﯽﻣ ﺺﺨﺸﻣ ﺍﺭ ﺮﺼﻨﻋ ﺪﻨﭼ (1) ﻡﻭﺩ ﺮﺘﻣﺍﺭﺎﭘ
.ﺪﺷ ﺪﻫﺍﻮﺨﻧ ﻪﻓﺎﺿﺍ ﯼﺪﯾﺪﺟ ﺮﺼﻨﻋ ﭻﯿﻫ .ﺪﻧﺍ ﻩﺪﺷ ﻑﺬﺣ ﺎﻫﺮﺘﻣﺍﺭﺎﭘ ﻪﯿﻘﺑ
slice()
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ .ﺪﻫﺩ ﯽﻣ ﺵﺮﺑ ﺪﯾﺪﺟ ﻪﯾﺍﺭﺁ ﮏﯾ ﻪﺑ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ ﺯﺍ ﻪﻌﻄﻗ ﮏﯾ slice()
ﺵﻭﺭ
ﺪﻫﺩ ﯽﻣ ﺵﺮﺑ ،ﺩﻮﺷ ﯽﻣ ﻉﻭﺮﺷ 1 ﻪﯾﺍﺭﺁ ﺮﺼﻨﻋ ﺯﺍ ﻪﮐ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ ﺯﺍ ﯽﺸﺨﺑ ﻝﺎﺜﻣ ﻦﯾﺍ
const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const citrus = fruits.slice(1);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The slice() Method</h2>
<p>Slice out a part of an array starting from array element 1 ("Orange"):</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const citrus = fruits.slice(1);
document.getElementById("demo").innerHTML = fruits + "<br><br>" + citrus;
</script>
</body>
</html>
.ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺪﯾﺪﺟ ﻪﯾﺍﺭﺁ ﮏﯾ slice()
ﺵﻭﺭ
.ﺪﻨﮐ ﯽﻤﻧ ﻑﺬﺣ ﻊﺒﻨﻣ ﻪﯾﺍﺭﺁ ﺯﺍ ﺍﺭ ﯼﺮﺼﻨﻋ ﭻﯿﻫ slice()
ﺵﻭﺭ
ﺪﻫﺩ ﯽﻣ ﺵﺮﺑ ،ﺩﻮﺷ ﯽﻣ ﻉﻭﺮﺷ 3 ﻪﯾﺍﺭﺁ ﺮﺼﻨﻋ ﺯﺍ ﻪﮐ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ ﺯﺍ ﯽﺸﺨﺑ ﻝﺎﺜﻣ ﻦﯾﺍ
const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const citrus = fruits.slice(3);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The slice() Method</h2>
<p>Slice out a part of an array starting from array element 3 ("Apple")</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const citrus = fruits.slice(3);
document.getElementById("demo").innerHTML = fruits + "<br><br>" + citrus;
</script>
</body>
</html>
.ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ slice(1, 3)
ﺪﻨﻧﺎﻣ ﻥﺎﻣﻮﮔﺭﺁ ﻭﺩ ﺪﻧﺍﻮﺗ ﯽﻣ slice()<
ﺪﻨﮐ ﯽﻣ ﺏﺎﺨﺘﻧﺍ (ﻪﻧ ﺎﻣﺍ) ﺎﺗ ﻭ start ﻥﺎﻣﻮﮔﺭﺁ ﺯﺍ ﺍﺭ ﺮﺻﺎﻨﻋ ﺪﺘﻣ ﺲﭙﺳ
const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const citrus = fruits.slice(1, 3);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The slice() Method</h2>
<p>When the slice() method is given two arguments, it selects array elements from the start argument, and up to (but not included) the end argument:</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const citrus = fruits.slice(1,3);
document.getElementById("demo").innerHTML = fruits + "<br><br>" + citrus;
</script>
</body>
</html>
slice()
،ﻝﻭﺍ ﯼﺎﻫ ﻝﺎﺜﻣ ﺪﻨﻧﺎﻣ ،ﺩﻮﺷ ﻑﺬﺣ ﻥﺎﯾﺎﭘ ﻥﺎﻣﻮﮔﺭﺁ ﺮﮔﺍ
const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const citrus = fruits.slice(2);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The slice() Method</h2>
<p>Slice out a part of an array starting from array element 2 ("Lemon"):</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const citrus = fruits.slice(2);
document.getElementById("demo").innerHTML = fruits + "<br><br>" + citrus;
</script>
</body>
</html>
toString()
ﺭﺎﮐﺩﻮﺧa ﻪﮐ ﺪﻨﮐ ﯽﻣ ﻞﯾﺪﺒﺗ ﺎﻣﺎﮐ ﺎﺑ ﻩﺪﺷ ﺍﺪﺟ ﻪﺘﺷﺭ ﮏﯾ ﻪﺑ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ ﺭﺎﮐﺩﻮﺧ ﺭﻮﻃ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
.ﺪﻨﮐ ﯽﻣ ﻕﺪﺻ ﺪﯾﺮﯿﮕﺑ ﯽﺟﻭﺮﺧ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ ﺪﯿﻨﮐ ﯽﻣ ﯽﻌﺳ ﺎﻤﺷ ﻪﮐ ﯽﻧﺎﻣﺯ ﻪﺸﯿﻤﻫ ﻦﯾﺍ
:ﺖﺷﺍﺩ ﺪﻨﻫﺍﻮﺧ ﯽﻧﺎﺴﮑﯾ ﻪﺠﯿﺘﻧ ﻝﺎﺜﻣ ﻭﺩ ﻦﯾﺍ
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits.toString();
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!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 fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p>JavaScript automatically converts an array to a comma separated string when a simple value is expected:</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits;
</script>
</body>
</html>
.ﺪﻨﺘﺴﻫ()toString ﺪﺘﻣ ﮏﯾ ﯼﺍﺭﺍﺩ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ءﺎﯿﺷﺍ ﻡﺎﻤﺗ
ﺩﺭﺍﺪﻧ ﺩﻮﺟﻭ ﻦﯾﺮﺗﻻﺎﺑ ﻦﺘﻓﺎﯾ ﯼﺍﺮﺑ ﯽﻠﺧﺍﺩ ﺩﺮﮑﻠﻤﻋ ﭻﯿﻫ
ﺪﯿﻨﮐ ﻞﺣ ﺍﺭ ﻞﮑﺸﻣ ﻦﯾﺍ ﻪﻧﻮﮕﭼ ﻪﮐ ﺖﻓﺮﮔ ﺪﯿﻫﺍﻮﺧ ﺩﺎﯾ ﻪﻣﺍﺩﺍ ﺭﺩ
.ﺖﺳﺍ ﻩﺪﺷ ﻩﺩﺍﺩ ﺶﺷﻮﭘ ﺵﺯﻮﻣﺁ ﻦﯾﺍ ﯼﺪﻌﺑ ﻞﺼﻓ ﺭﺩ ﺎﻫ ﻪﯾﺍﺭﺁ ﯼﺯﺎﺳ ﺐﺗﺮﻣ
:ﺪﯾﻭﺮﺑ ﺎﻣ ﺱﺭﺩﺁ ﻪﺑ ،ﻪﯾﺍﺭﺁ ﻞﻣﺎﮐ ﻊﺟﺮﻣ ﮏﯾ ﯼﺍﺮﺑ
.ﻞﻣﺎﮐ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ ﻊﺟﺮﻣ
ﺖﺳﺍ ﺎﻫ ﻪﯾﺍﺭﺁ ﻪﻤﻫ ﺯﺍ ﯽﯾﺎﻫ ﻪﻧﻮﻤﻧ ﻭ ﺕﺎﺤﯿﺿﻮﺗ ﯼﻭﺎﺣ ﻊﺟﺮﻣ