ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺶﯾﺎﻤﻧ ءﺎﯿﺷﺍ


فهرست مطالب

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


؟ﻢﯿﻫﺩ ﺶﯾﺎﻤﻧ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ءﺎﯿﺷﺍ ﻪﻧﻮﮕﭼ

.ﺖﺷﺍﺩ ﺪﻫﺍﻮﺧ [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 ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ

:ﺩﺮﮐ ﻞﯾﺪﺒﺗ ﻪﯾﺍﺭﺁ ﻪﺑ 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)


()JSON.stringify ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ

(ﺩﺮﮐ ﻞﯾﺪﺒﺗ ﻪﺘﺷﺭ ﻪﺑ) ﺩﺮﮐ ﻪﺘﺷﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻊﺑﺎﺗ ﺎﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﺮﻫ

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>

Stringify ﻊﺑﺍﻮﺗ

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>

Stringify ﺎﻫ ﻪﯾﺍﺭﺁ

:ﺩﺮﮐ ﯼﺪﻨﺑﻪﺘﺷﺭ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫﻪﯾﺍﺭﺁ ﻥﺍﻮﺗﯽﻣ ﻦﯿﻨﭽﻤﻫ

ﻝﺎﺜﻣ

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 ﺩﺎﻤﻧ ﻝﺎﺒﻧﺩ ﻪﺑ ﻪﺘﺷﺭ ﮏﯾ ﻪﺠﯿﺘﻧ

["ﻦﯿﺟ" ،"ﯽﻟﺎﺳ" ،"ﺮﺘﯿﭘ" ،"ﻥﺎﺟ"]