:ﺖﺳﺍ JSON ﻪﺘﺷﺭ ﮏﯾ ﻦﯾﺍ
'["Ford", "BMW", "Fiat"]'
:ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﻪﻤﻠﮐ ﯽﻌﻗﺍﻭ ﯼﺎﻨﻌﻣ ﻪﺑ JSON ﻪﯾﺍﺭﺁ ﮏﯾ JSON ﻪﺘﺷﺭ ﻞﺧﺍﺩ ﺭﺩ
["Ford", "BMW", "Fiat"]
.ﺪﻨﺘﺴﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ ﺎﻫ ﻪﯾﺍﺭﺁ ﻪﺑﺎﺸﻣ ﺎًﺒﯾﺮﻘﺗ JSON ﺭﺩ ﺎﻫ ﻪﯾﺍﺭﺁ
ﺪﺷﺎﺑ string، number، object، array، boolean ﻉﻮﻧ ﺯﺍ ﺪﯾﺎﺑ ﻪﯾﺍﺭﺁ ﺮﯾﺩﺎﻘﻣ ،JSON ﺭﺩ
ﺪﻨﺷﺎﺑ ﯼﺮﮕﯾﺩ ﺮﺒﺘﻌﻣ ﺮﻫ ﻪﻓﺎﺿﺍ ﻪﺑ ﻻﺎﺑ ﺩﺭﺍﻮﻣ ﻪﻤﻫ ﺪﻨﻧﺍﻮﺗﯽﻣ ﺎﻫﻪﯾﺍﺭﺁ ﺮﯾﺩﺎﻘﻣ ،ﺖﭙﯾﺮﮑﺳ
ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ Literal ﮏﯾ ﺯﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ ﮏﯾ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ
myArray = ["Ford", "BMW", "Fiat"];
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Creating an Array from a Literal</h2>
<p id="demo"></p>
<script>
const myArray = ["Ford", "BMW", "Fiat"];
document.getElementById("demo").innerHTML = myArray;
</script>
</body>
</html>
ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ ﮏﯾ JSON ﻪﺘﺷﺭ ﻪﯾﺰﺠﺗ ﺎﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ
myJSON = '["Ford", "BMW", "Fiat"]';
myArray = JSON.parse(myJSON);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Creating an Array from JSON</h2>
<p id="demo"></p>
<script>
const myJSON = '["Ford", "BMW", "Fiat"]';
const myArray = JSON.parse(myJSON);
document.getElementById("demo").innerHTML = myArray;
</script>
</body>
</html>
:ﺪﯾﺭﺍﺩ ﯽﺳﺮﺘﺳﺩ ﺺﺧﺎﺷ ﺱﺎﺳﺍ ﺮﺑ ﻪﯾﺍﺭﺁ ﺮﯾﺩﺎﻘﻣ ﻪﺑ ﺎﻤﺷ
myArray[0];
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>Access an Array by Index</h1>
<p id="demo"></p>
<script>
const myJSON = '["Ford", "BMW", "Fiat"]';
const myArray = JSON.parse(myJSON);
document.getElementById("demo").innerHTML = myArray[0];
</script>
</body>
</html>
:ﺪﻨﺷﺎﺑ ﯽﯾﺎﻫ ﻪﯾﺍﺭﺁ ﯼﻭﺎﺣ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﺎﯿﺷﺍ
{
"name":"John",
"age":30,
"cars":["Ford", "BMW", "Fiat"]
}
:ﺪﯾﺭﺍﺩ ﯽﺳﺮﺘﺳﺩ ﺺﺧﺎﺷ ﺱﺎﺳﺍ ﺮﺑ ﻪﯾﺍﺭﺁ ﺮﯾﺩﺎﻘﻣ ﻪﺑ ﺎﻤﺷ
myObj.cars[0];
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Access Array Values</h2>
<p id="demo"></p>
<script>
const myJSON = '{"name":"John", "age":30, "cars":["Ford", "BMW", "Fiat"]}';
const myObj = JSON.parse(myJSON);
document.getElementById("demo").innerHTML = myObj.cars[0];
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﺍﺪﯿﭘ ﯽﺳﺮﺘﺳﺩ ﻪﯾﺍﺭﺁ ﺮﯾﺩﺎﻘﻣ ﻪﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ for in
ﻪ
for (let i in myObj.cars) {
x
+= myObj.cars[i];
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Looping an Array</h2>
<p id="demo"></p>
<script>
const myJSON = '{"name":"John", "age":30, "cars":["Ford", "BMW", "Fiat"]}';
const myObj = JSON.parse(myJSON);
let text = "";
for (let i in myObj.cars) {
text += myObj.cars[i] + ", ";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ for
ﻪﻘﻠﺣ ﮏﯾ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﯾ
for (let i
= 0; i < myObj.cars.length; i++) {
x
+= myObj.cars[i];
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>Looping an Array</h2>
<p id="demo"></p>
<script>
const myJSON = '{"name":"John", "age":30, "cars":["Ford", "BMW", "Fiat"]}';
const myObj = JSON.parse(myJSON);
let text = "";
for (let i = 0; i < myObj.cars.length; i++) {
text += myObj.cars[i] + ", ";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>