.ﺖﺷﺍﺩ ﺪﻫﺍﻮﺧ [object Object] ﯽﺟﻭﺮﺧ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﺶﯾﺎﻤﻧ
const person = {
name: "John",
age: 30,
city: "New York"
};
document.getElementById("demo").innerHTML = person;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>
<p>Displaying a JavaScript object will output [object Object]:</p>
<p id="demo"></p>
<script>
const person = {
name: "John",
age: 30,
city: "New York"
};
document.getElementById("demo").innerHTML = person;
</script>
</body>
</html>
:ﺯﺍ ﺪﻨﺗﺭﺎﺒﻋ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ءﺎﯿﺷﺍ ﺶﯾﺎﻤﻧ ﯼﺍﺮﺑ ﺞﯾﺍﺭ ﯼﺎﻫ ﻞﺣ ﻩﺍﺭ ﺯﺍ ﯽﺧﺮﺑ
:ﺩﺍﺩ ﺶﯾﺎﻤﻧ ﯼﺍ ﻪﺘﺷﺭ ﺕﺭﻮﺻ ﻪﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﯽﺷ ﮏﯾ ﯼﺎﻫ ﯽﮔﮋﯾﻭ
const person = {
name: "John",
age: 30,
city: "New York"
};
document.getElementById("demo").innerHTML =
person.name + "," + person.age + "," + person.city;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>
<p>Display object properties:</p>
<p id="demo"></p>
<script>
const person = {
name: "John",
age: 30,
city: "New York"
};
document.getElementById("demo").innerHTML = person.name + ", " + person.age + ", " + person.city;
</script>
</body>
</html>
:ﺩﺮﮐ ﯼﺭﻭﺁ ﻊﻤﺟ ﻪﻘﻠﺣ ﮏﯾ ﺭﺩ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﯽﺷ ﮏﯾ ﯼﺎﻫ ﯽﮔﮋﯾﻭ
const person = {
name: "John",
age: 30,
city: "New York"
};
let txt = "";
for (let x in person) {
txt += person[x] + " ";
};
document.getElementById("demo").innerHTML = txt;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>
<p>Display object properties:</p>
<p id="demo"></p>
<script>
const person = {
name: "John",
age: 30,
city: "New York"
};
let txt = "";
for (let x in person) {
txt += person[x] + " ";
};
document.getElementById("demo").innerHTML = txt;
</script>
</body>
</html>
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻪﻘﻠﺣ ﺭﺩ person[x] ﺯﺍ ﺪﯾﺎﺑ ﺎﻤﺷ
person.x ﺩﺮﮐ ﺪﻫﺍﻮﺨﻧ ﺭﺎﮐ (ﺍﺮﯾﺯ x ﺖﺳﺍ ﺮﯿﻐﺘﻣ ﮏﯾ).
:ﺩﺮﮐ ﻞﯾﺪﺒﺗ ﻪﯾﺍﺭﺁ ﻪﺑ Object.values()
ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﻥﺍ
const person = {
name: "John",
age: 30,
city: "New York"
};
const myArray = Object.values(person);
myArray
ﺖﺳﺍ ﺶﯾﺎﻤﻧ ﻩﺩﺎﻣﺁ ﻪﮐ ﺖﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﯾﺍﺭﺁ ﮏﯾ
const person = {
name: "John",
age: 30,
city: "New York"
};
const myArray = Object.values(person);
document.getElementById("demo").innerHTML = myArray;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>
<p>Object.values() converts an object to an array.</p>
<p id="demo"></p>
<script>
const person = {
name: "John",
age: 30,
city: "New York"
};
document.getElementById("demo").innerHTML = Object.values(person);
</script>
</body>
</html>
Object.values()
ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﯽﻠﺻﺍ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﻤﻫ ﺭ
54 (2016) | 14 (2016) | 47 (2016) | 10 (2016) | 41 (2016) |
(ﺩﺮﮐ ﻞﯾﺪﺒﺗ ﻪﺘﺷﺭ ﻪﺑ) ﺩﺮﮐ ﻪﺘﺷﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻊﺑﺎﺗ ﺎﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﺮﻫ
const person = {
name: "John",
age: 30,
city: "New York"
};
let myString = JSON.stringify(person);
myString
ﺖﺳﺍ ﺶﯾﺎﻤﻧ ﻩﺩﺎﻣﺁ ﻪﮐ ﺖﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ ﮏﯾ
const person = {
name: "John",
age: 30,
city: "New York"
};
let myString = JSON.stringify(person);
document.getElementById("demo").innerHTML = myString;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>
<p>Display properties in JSON format:</p>
<p id="demo"></p>
<script>
const person = {
name: "John",
age: 30,
city: "New York"
};
document.getElementById("demo").innerHTML = JSON.stringify(person);
</script>
</body>
</html>
:ﺩﻮﺑ ﺪﻫﺍﻮﺧ JSON ﺩﺎﻤﻧ ﻝﺎﺒﻧﺩ ﻪﺑ ﻪﺘﺷﺭ ﮏﯾ ﻪﺠﯿﺘﻧ
{"name":"50:"ﻦﺳ"،"ﻥﺎﺟ"city":"ﮎﺭﻮﯾﻮﯿﻧ"}
JSON.stringify()
ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﯽﻠﺻﺍ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﻤﻫ
JSON.stringify
ﺪﻨﮐ ﯽﻣ ﻞﯾﺪﺒﺗ ﻪﺘﺷﺭ ﻪﺑ ﺍﺭ ﺎﻫ ﺦﯾﺭﺎﺗ:
const person = {
name: "John",
today: new Date()
};
let myString = JSON.stringify(person);
document.getElementById("demo").innerHTML = myString;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>
<p>JSON.stringify will convert dates into strings:</p>
<p id="demo"></p>
<script>
var person = {
name: "John",
today: new Date()
};
document.getElementById("demo").innerHTML = JSON.stringify(person);
</script>
</body>
</html>
JSON.stringify
ﻪﺘﺷﺭ ﺍﺭ ﻊﺑﺍﻮﺗﯽﻤﻧ ﯼﺪﻨﺑﺪﻨﮐ:
const person = {
name: "John",
age: function () {return 30;}
};
let myString = JSON.stringify(person);
document.getElementById("demo").innerHTML = myString;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>
<p>JSON.stringify will not stringify functions:</p>
<p id="demo"></p>
<script>
const person = {
name: "John",
age: function () {return 30;}
};
document.getElementById("demo").innerHTML = JSON.stringify(person);
</script>
</body>
</html>
."ﺩﺮﮐ ﺖﯿﺒﺜﺗ" ﺍﺭ ﻞﮑﺸﻣ ﻦﯾﺍ ﻥﺍﻮﺗﯽﻣ ،ﺪﯿﻨﮐ ﻞﯾﺪﺒﺗ ﻪﺘﺷﺭ ﻪﺑ ﺍﺭ ﻊﺑﺍﻮﺗ ﯼﺪﻨﺑﻪﺘﺷﺭ ﺯﺍ ﻞﺒ
const person = {
name: "John",
age: function () {return 30;}
};
person.age = person.age.toString();
let myString = JSON.stringify(person);
document.getElementById("demo").innerHTML = myString;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Display Objects</h2>
<p>JSON.stringify will not stringify functions.</p>
<p>You have to convert functions to strings first:</p>
<p id="demo"></p>
<script>
const person = {
name: "John",
age: function () {return 30;}
};
person.age = person.age.toString();
document.getElementById("demo").innerHTML = JSON.stringify(person);
</script>
</body>
</html>
:ﺩﺮﮐ ﯼﺪﻨﺑﻪﺘﺷﺭ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫﻪﯾﺍﺭﺁ ﻥﺍﻮﺗﯽﻣ ﻦﯿﻨﭽﻤﻫ
const arr = ["John", "Peter", "Sally", "Jane"];
let myString = JSON.stringify(arr);
document.getElementById("demo").innerHTML = myString;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p>JSON.stringify can stringify arrays:</p>
<p id="demo"></p>
<script>
const arr = ["John", "Peter", "Sally", "Jane"];
document.getElementById("demo").innerHTML = JSON.stringify(arr);
</script>
</body>
</html>
:ﺩﻮﺑ ﺪﻫﺍﻮﺧ JSON ﺩﺎﻤﻧ ﻝﺎﺒﻧﺩ ﻪﺑ ﻪﺘﺷﺭ ﮏﯾ ﻪﺠﯿﺘﻧ
["ﻦﯿﺟ" ،"ﯽﻟﺎﺳ" ،"ﺮﺘﯿﭘ" ،"ﻥﺎﺟ"]