ES5 ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ


فهرست مطالب

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

ECMAScript 2009، ﻥﺍﻮﻨﻋ ﻪﺑ ﻦﯿﻨﭽﻤﻫ ES5 ﺩﻮﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﻠﺻﺍ ﻪﺨﺴﻧ ﻦﯿﻟﻭﺍ ،ﺩﻮﺷ ﯽﻣ ﻪﺘﺧﺎﻨﺷ.

.ﺪﻫﺩ ﯽﻣ ﺡﺮﺷ ﺍﺭ ES5 ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﻦﯾﺮﺘﻤﻬﻣ ﻞﺼﻓ ﻦﯾﺍ

ES5 ﯼﺎﻫ ﯽﮔﮋﯾﻭ

  • "ﻦﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺖﺨﺳ"

  • [ﻩﺭﺎﻤﺷ]ﻪﺘﺷﺭ ﻪﺑ ﯽﺳﺮﺘﺳﺩ

  • ﯽﻄﺧ ﺪﻨﭼ ﯼﺎﻫ ﻪﺘﺷﺭ

  • String.trim()

  • Array.isArray()

  • ()ﺮﻫ ﯼﺍﺮﺑ ﻪﯾﺍﺭﺁ

  • () ﻪﯾﺍﺭﺁ ﻪﺸﻘﻧ

  • () ﻪﯾﺍﺭﺁ ﺮﺘﻠﯿﻓ

  • ()ﻪﯾﺍﺭﺁ ﺶﻫﺎﮐ

  • ()reduceRight ﻪﯾﺍﺭﺁ

  • ()ﺮﻫ ﻪﯾﺍﺭﺁ

  • ()ﺪﻨﭼ ﻪﯾﺍﺭﺁ

  • ()indexOf ﻪﯾﺍﺭﺁ

  • ()lastIndexOf ﻪﯾﺍﺭﺁ

  • JSON.parse()

  • JSON.stringify()

  • Date.now()

  • ()toISOSstring ﺦﯾﺭﺎﺗ

  • ()JSON ﻪﺑ ﺦﯾﺭﺎﺗ

  • ﺎﻫ ﻩﺪﻨﻨﮐ ﻢﯿﻈﻨﺗ ﻭ ﻥﺎﮔﺪﻧﺮﯿﮔ ﮎﻼﻣﺍ

  • ﻝﺍﻮﻣﺍ ﻡﺎﻧ ﻥﺍﻮﻨﻋ ﻪﺑ ﻩﺪﺷ ﻭﺭﺯﺭ ﺕﺎﻤﻠﮐ

  • ﯽﺷ ﯼﺎﻫ ﺵﻭﺭ

  • Object defineProperty()

  • ()bind ﻊﺑﺎﺗ

  • ﺭﺍﺩ ﻪﻟﺎﺒﻧﺩ ﯼﺎﻫﺎﻣﺎﮐ


ﺮﮔﺭﻭﺮﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ

ES5 ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﻤﻫ ﺭﺩ ﻞﻣﺎﮐ ﺭﻮﻃ ﻪ

Chrome IE Edge Firefox Safari Opera
Yes 9.0 Yes Yes Yes Yes

"ﺖﺨﺳ ﻩﺩﺎﻔﺘﺳﺍ" ﻞﻤﻌﻟﺍﺭﻮﺘﺳﺩ

"use strict" ﺩﻮﺷ ﺍﺮﺟﺍ "ﻖﯿﻗﺩ ﺖﻟﺎﺣ" ﺭﺩ ﺪﯾﺎﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭ

.ﺪﯿﻨﮑﻧ ﻩﺩﺎﻔﺘﺳﺍ ﻩﺪﺸﻧ ﻡﻼﻋﺍ ﯼﺎﻫﺮﯿﻐﺘﻣ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺖﺨﺳ ﺖﻟﺎﺣ ﺎﺑ ،ﻝﺎﺜﻣ ﯼﺍﺮﺑ

،ﺪﯿﺴﯾﻮﻨﺑ ﯼﺮﺗ ﮎﺎﭘ ﺪﮐ ﺎﺗ ﺪﻨﮐ ﯽﻣ ﮏﻤﮐ ﺎﻤﺷ ﻪﺑ ﻦﯾﺍ .ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺩﻮﺧ ﯼﺎﻫ ﻪﻣﺎﻧﺮﺑ ﻪﻤﻫ ﺭﺩ ﺖﺨﺳ

"ﺖﺨﺳ ﻩﺩﺎﻔﺘﺳﺍ" ﺪﻨﻨﮐ ﯽﻤﻧ ﺩﺎﺠﯾﺍ ﯽﯾﺎﻄﺧ ،ﺪﻨﻨﮑﻧ ﮎﺭﺩ ﺍﺭ ﻥﺁ

.ﺪﯿﻧﺍﻮﺨﺑ ﺮﺘﺸﯿﺑ JS Strict Mode ﺭﺩ


ﺎﻫ ﻪﺘﺷﺭ ﺭﺩ ﯽﮔﮋﯾﻭ ﻪﺑ ﯽﺳﺮﺘﺳﺩ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺺﺨﺸﻣ ﺭﺍﺪﻘﻣ ﮏﯾ ﺭﺩ ﺍﺭ ﺮﺘﮐﺍﺭﺎﮐ charAt() ﺵﻭ

ﻝﺎﺜﻣ

var str = "HELLO WORLD";
str.charAt(0);            // returns H

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript String Methods</h2>

<p>The charAt() method returns the character at a given position in a string:</p>

<p id="demo"></p>

<script>
var str = "HELLO WORLD";
document.getElementById("demo").innerHTML = str.charAt(0);
</script>
</body>
</html>

ES5 ﺪﻫﺩ ﯽﻣ ﺎﻫ ﻪﺘﺷﺭ ﺭﺩ ﺍﺭ ﯽﮔﮋﯾﻭ ﻪﺑ ﯽﺳﺮﺘﺳﺩ ﻩﺯﺎﺟﺍ:

ﻝﺎﺜﻣ

var str = "HELLO WORLD";
str[0];                   // returns H

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript String Methods</h2>

<p>ECMAScript 5 allows property acces on strings:</p>

<p id="demo"></p>

<script>
var str = "HELLO WORLD";
document.getElementById("demo").innerHTML = str[0];
</script>
</body>
</html>

.ﺪﺷﺎﺑ ﯽﻨﯿﺑ ﺶﯿﭘ ﻞﺑﺎﻗ ﺮﯿﻏ ﯽﻤﮐ ﺖﺳﺍ ﻦﮑﻤﻣ ﻪﺘﺷﺭ ﺭﺩ ﯽﮔﮋﯾﻭ ﻪﺑ ﯽﺳﺮﺘﺳﺩ

.ﺪﯿﻧﺍﻮﺨﺑ ﺮﺘﺸﯿﺑ JS String Methods ﺭﺩ


ﻂﺧ ﻦﯾﺪﻨﭼ ﺭﺩ ﺎﻫ ﻪﺘﺷﺭ

ﻝﺎﺜﻣ

 "Hello \
Dolly!";

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>

<p>
You can break a code line within a text string with a backslash.
</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = "Hello \
Dolly!";
</script>

</body>
</html>

ﺪﻧﻮﺷ ﻥﺎﻣﺭﺩ ﺮﺗ ﯽﻤﯾﺪﻗ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﺖﺳﺍ ﻦﮑﻤﻣ
.ﺪﺷﺎﺑ ﻪﺘﺷﺍﺪﻧ ﯽﻧﺎﻬﺟ ﯽﻧﺎﺒﯿﺘﺸﭘ ﺖﺳﺍ ﻦﮑﻤﻣ\ﺵﻭﺭ

ﺖﺳﺍ ﻪﺘﺷﺭ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ،ﻪﻤﻠﮐ ﯽﻌﻗﺍﻭ ﯼﺎﻨﻌﻣ ﻪﺑ ﻪﺘﺷﺭ ﮏﯾ ﻦﺘﺴﮑﺷ ﯼﺍﺮﺑ ﺮﺗ ﻦﺌﻤﻄﻣ ﻩﺍﺭ ﮏﯾ

ﻝﺎﺜﻣ

 "Hello " + 
"Dolly!";

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>

<p>The safest way to break a code line in a string is using string addition.</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = "Hello " +
"Dolly!";
</script>

</body>
</html>

ﻝﺍﻮﻣﺍ ﻡﺎﻧ ﻥﺍﻮﻨﻋ ﻪﺑ ﻩﺪﺷ ﻭﺭﺯﺭ ﺕﺎﻤﻠﮐ

ES5 ﺪﻫﺩ ﯽﻣ ﻩﺯﺎﺟﺍ ﯽﯾﺍﺭﺍﺩ ﻡﺎﻧ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﻩﺪﺷ ﻭﺭﺯﺭ ﺕﺎﻤﻠﮐ:

ﯽﺷ ﻝﺎﺜﻣ

 var obj = {name: "John", new: "yes"}

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>ECMAScript 5</h1>

<p>ECMAScript 5 allows reserved words as property names.</p>
<p id="demo"></p>

<script>
var obj = {name: "John", new: "yes"};
document.getElementById("demo").innerHTML = obj.new;
</script>

</body>
</html>



trim() ﻪﺘﺷﺭ

.ﺪﻨﮐ ﯽﻣ ﻑﺬﺣ ﻪﺘﺷﺭ ﻑﺮﻃ ﻭﺩ ﺯﺍ ﺍﺭ ﯽﻟﺎﺧ ﯼﺎﻀﻓ trim() ﺵﻭﺭ

ﻝﺎﺜﻣ

var str = "       Hello World!        ";
alert(str.trim());

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>
<h2>The trim() Method</h2>

<p id="demo"></p>

<script>
let text1 = "     Hello World!     ";
let text2 = text1.trim();

document.getElementById("demo").innerHTML =
"Length text1 = " + text1.length + "<br>Length text2 = " + text2.length;
</script>

</body>
</html>

.ﺪﯿﻧﺍﻮﺨﺑ ﺮﺘﺸﯿﺑ JS String Methods ﺭﺩ



Array.isArray()

.ﺮﯿﺧ ﺎﯾ ﺖﺳﺍ ﻪﯾﺍﺭﺁ ﮏﯾ ﯽﺷ ﮏﯾ ﺎﯾﺁ ﻪﮐ ﺪﻨﮐ ﯽﻣ ﯽﺳﺭﺮﺑ isArray()

ﻝﺎﺜﻣ

function myFunction() {
  var fruits = ["Banana", "Orange", "Apple", "Mango"];
  var x = document.getElementById("demo");
    x.innerHTML = Array.isArray(fruits);
}

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The isArray() Method</h2>

<p>Click the button to check if "fruits" is an array.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
  var fruits = ["Banana", "Orange", "Apple", "Mango"];
  var x = document.getElementById("demo");
  x.innerHTML = Array.isArray(fruits);
}
</script>

</body>
</html>

.ﺪﯿﻧﺍﻮﺨﺑ ﺮﺘﺸﯿﺑ JS Arrays ﺭﺩ


forEach() ﻪﯾﺍﺭﺁ

.ﺪﻨﮐ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺭﺎﺒﮑﯾ ﻪﯾﺍﺭﺁ ﺮﺼﻨﻋ ﺮﻫ ﯼﺍﺮﺑ ﺍﺭ ﻊﺑﺎﺗ ﮏﯾ forEac

ﻝﺎﺜﻣ

var txt = "";
var numbers = [45, 4, 9, 16, 25];
numbers.forEach(myFunction);

function myFunction(value) {
   
txt = txt + value + "<br>"; 
}

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array.forEach()</h2>

<p>Calls a function once for each array element.</p>

<p id="demo"></p>

<script>
var txt = "";
var numbers = [45, 4, 9, 16, 25];
numbers.forEach(myFunction);
document.getElementById("demo").innerHTML = txt;

function myFunction(value) {
  txt = txt + value + "<br>"; 
}
</script>

</body>
</html>

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ JS Array Iteration Methods ﺭﺩ


map() ﻪﯾﺍﺭﺁ

:ﺪﻨﮐ ﯽﻣ ﺏﺮﺿ 2 ﺭﺩ ﺍﺭ ﻪﯾﺍﺭﺁ ﺮﻫ ﺭﺍﺪﻘﻣ ﻝﺎﺜﻣ ﻦﯾﺍ

ﻝﺎﺜﻣ

var numbers1 = [45, 4, 9, 16, 25];
var numbers2 = numbers1.map(myFunction);
  
function myFunction(value) {
  return value * 2;
}

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array.map()</h2>

<p>Creates a new array by performing a function on each array element.</p>

<p id="demo"></p>

<script>
var numbers1 = [45, 4, 9, 16, 25];
var numbers2 = numbers1.map(myFunction);

document.getElementById("demo").innerHTML = numbers2;

function myFunction(value, index, array) {
  return value * 2;
}
</script>

</body>
</html>

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ JS Array Iteration Methods ﺭﺩ


filter() ﻪﯾﺍﺭﺁ

:ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ 18 ﺯﺍ ﺮﺘﮔﺭﺰﺑ ﺭﺍﺪﻘﻣ ﺎﺑ ﺮﺻﺎﻨﻋ ﺯﺍ ﺪﯾﺪﺟ ﻪﯾﺍﺭﺁ ﮏﯾ ﻝﺎﺜﻣ ﻦﯾﺍ

ﻝﺎﺜﻣ

 var numbers = [45, 4, 9, 16, 25];
var over18 = 
  numbers.filter(myFunction);
function myFunction(value) {
  return value > 18;
} 

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array.filter()</h2>

<p>Creates a new array with all array elements that passes a test.</p>

<p id="demo"></p>

<script>
var numbers = [45, 4, 9, 16, 25];
var over18 = numbers.filter(myFunction);

document.getElementById("demo").innerHTML = over18;

function myFunction(value, index, array) {
  return value > 18;
}
</script>

</body>
</html>

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ JS Array Iteration Methods ﺭﺩ


reduce() ﻪﯾﺍﺭﺁ

:ﺪﻨﮐ ﯽﻣ ﺍﺪﯿﭘ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ ﺩﺍﺪﻋﺍ ﻡﺎﻤﺗ ﻉﻮﻤﺠﻣ ﻝﺎﺜﻣ ﻦﯾﺍ

ﻝﺎﺜﻣ

 var numbers1 = [45, 4, 9, 16, 25];
var sum = numbers1.reduce(myFunction);
  
function myFunction(total, value) {
  
  return total + value;
} 

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array.reduce()</h2>

<p>This example finds the sum of all numbers in an array:</p>

<p id="demo"></p>

<script>
var numbers = [45, 4, 9, 16, 25];
var sum = numbers.reduce(myFunction);

document.getElementById("demo").innerHTML = "The sum is " + sum;

function myFunction(total, value, index, array) {
  return total + value;
}
</script>

</body>
</html>

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ JS Array Iteration Methods ﺭﺩ


reduceRight() ﻪﯾﺍﺭﺁ

:ﺪﻨﮐ ﯽﻣ ﺍﺪﯿﭘ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ ﺩﺍﺪﻋﺍ ﻡﺎﻤﺗ ﻉﻮﻤﺠﻣ ﻦﯿﻨﭽﻤﻫ ﻝﺎﺜﻣ ﻦﯾﺍ

ﻝﺎﺜﻣ

 var numbers1 = [45, 4, 9, 16, 25];
var sum = numbers1.reduceRight(myFunction);
  
function myFunction(total, value) {
  return total + value;
} 

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array.reduceRight()</h2>

<p>This example finds the sum of all numbers in an array:</p>

<p id="demo"></p>

<script>
var numbers = [45, 4, 9, 16, 25];
var sum = numbers.reduceRight(myFunction);

document.getElementById("demo").innerHTML = "The sum is " + sum;

function myFunction(total, value) {
  return total + value;
}
</script>

</body>
</html>

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ JS Array Iteration Methods ﺭﺩ


every() ﻪﯾﺍﺭﺁ

:ﺪﻨﺘﺴﻫ 18 ﺯﺍ ﺶﯿﺑ ﺮﯾﺩﺎﻘﻣ ﻪﻤﻫ ﺎﯾﺁ ﻪﮐ ﺪﻨﮐ ﯽﻣ ﯽﺳﺭﺮﺑ ﻝﺎﺜﻣ ﻦﯾﺍ

ﻝﺎﺜﻣ

 var numbers = [45, 4, 9, 16, 25];
var allOver18 = 
  numbers.every(myFunction);
function myFunction(value) {
  return 
  value > 18;
} 

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array.every()</h2>

<p>The every() method checks if all array values pass a test.</p>

<p id="demo"></p>

<script>
var numbers = [45, 4, 9, 16, 25];
var allOver18 = numbers.every(myFunction);

document.getElementById("demo").innerHTML = "All over 18 is " + allOver18;

function myFunction(value, index, array) {
  return value > 18;
}
</script>

</body>
</html>

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ JS Array Iteration Methods ﺭﺩ


some() ﻪﯾﺍﺭﺁ

:ﺪﻨﺘﺴﻫ 18 ﺯﺍ ﺶﯿﺑ ﺮﯾﺩﺎﻘﻣ ﺯﺍ ﯽﺧﺮﺑ ﺎﯾﺁ ﻪﮐ ﺪﻨﮐ ﯽﻣ ﯽﺳﺭﺮﺑ ﻝﺎﺜﻣ ﻦﯾﺍ

ﻝﺎﺜﻣ

 var numbers = [45, 4, 9, 16, 25];
var allOver18 = 
  numbers.some(myFunction);
function myFunction(value) {
  return 
  value > 18;
} 

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array.some()</h2>

<p>The some() method checks if some array values pass a test.</p>

<p id="demo"></p>

<script>
var numbers = [45, 4, 9, 16, 25];
var allOver18 = numbers.some(myFunction);

document.getElementById("demo").innerHTML = "Some over 18 is " + allOver18;

function myFunction(value) {
  return value > 18;
}
</script>

</body>
</html>

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ JS Array Iteration Methods ﺭﺩ


indexOf() ﻪﯾﺍﺭﺁ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻥﺁ ﺖﯿﻌﻗﻮﻣ ﻭ ﺪﯿﻨﮐ ﻮﺠﺘﺴﺟ ﺮﺼﻨﻋ ﺭﺍﺪﻘﻣ ﮏﯾ ﯼﺍﺮﺑ ﺍﺭ ﻪﯾﺍﺭﺁ ﮏﯾ

ﻝﺎﺜﻣ

var fruits = ["Banana", "Orange", "Apple", "Mango"];
var a = fruits.indexOf("Apple");

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The indexOf() Method</h2>

<p id="demo"></p>

<script>
const fruits = ["Apple", "Orange", "Apple", "Mango"];
let position = fruits.indexOf("Apple") + 1;

document.getElementById("demo").innerHTML = "Apple is found in position " + position;
</script>

</body>
</html>

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ JS Array Iteration Methods ﺭﺩ


lastIndexOf() ﻪﯾﺍﺭﺁ

lastIndexOf() ﻥﺎﻤﻫ indexOf

ﻝﺎﺜﻣ

var fruits = ["Banana", "Orange", "Apple", "Mango"];
var a = fruits.lastIndexOf("Apple");

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The lastIndexOf() Method</h2>

<p id="demo"></p>

<script>
const fruits = ["Apple", "Orange", "Apple", "Mango"];
let position = fruits.lastIndexOf("Apple") + 1;

document.getElementById("demo").innerHTML = "Apple is found in position " + position;
</script>

</body>
</html>

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ JS Array Iteration Methods ﺭﺩ


JSON.parse()

.ﺖﺳﺍ ﺭﻭﺮﺳ ﺏﻭ ﮏﯾ ﺯﺍ ﺎﻫ ﻩﺩﺍﺩ ﺖﻓﺎﯾﺭﺩ JSON ﺞﯾﺍﺭ ﯼﺎﻫﺩﺮﺑﺭﺎﮐ ﺯﺍ ﯽﮑﯾ

:ﺪﯾﺍ ﻩﺩﺮﮐ ﺖﻓﺎﯾﺭﺩ ﺭﻭﺮﺳ ﺏﻭ ﮏﯾ ﺯﺍ ﺍﺭ ﻦﺘﻣ ﻪﺘﺷﺭ ﻦﯾﺍ ﺪﯿﻨﮐ ﺭﻮﺼﺗ

'{"name":"John", "age":30, "city":"New York"}'

:ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﻪﺑ ﻦﺘﻣ ﻞﯾﺪﺒﺗ ﯼﺍﺮﺑ JSON.p

var obj = JSON.parse('{"name":"John", "age":30, "city":"New 
  York"}');

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>Creating an Object from a JSON String</h2>

<p id="demo"></p>

<script>
const txt = '{"name":"John", "age":30, "city":"New York"}'
const obj = JSON.parse(txt);
document.getElementById("demo").innerHTML = obj.name + ", " + obj.age;
</script>

</body>
</html>

.ﺪﯿﻧﺍﻮﺨﺑ ﺮﺘﺸﯿﺑ ﺎﻣ JSON ﺵﺯﻮﻣﺁ ﺭﺩ


JSON.stringify()

.ﺖﺳﺍ ﺏﻭ ﺭﻭﺮﺳ ﻪﺑ ﻩﺩﺍﺩ ﻝﺎﺳﺭﺍ JSON ﺞﯾﺍﺭ ﯼﺎﻫﺩﺮﺑﺭﺎﮐ ﺯﺍ ﯽﮑﯾ

ﺪﻨﺷﺎﺑ ﺪﯾﺎﺑ ﺎﻫ ﻩﺩﺍﺩ ،ﺏﻭ ﺭﻭﺮﺳ ﻪﺑ ﻩﺩﺍﺩ ﻝﺎﺳﺭﺍ ﻡﺎﮕﻨﻫ

:ﻢﯾﺭﺍﺩ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ ﺍﺭ ﯽﺷ ﻦﯾﺍ ﺪﯿﻨﮐ ﺭﻮﺼﺗ

var obj = {name:"John", age:30, city:"New York"};

.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻪﺘﺷﺭ ﻪﺑ ﻥﺁ ﻞﯾﺪﺒﺗ ﯼﺍﺮﺑ JSON.stringify()

var myJSON = JSON.stringify(obj);

.ﺩﻮﺑ ﺪﻫﺍﻮﺧ JSON ﺩﺎﻤﻧ ﻝﺎﺒﻧﺩ ﻪﺑ ﻪﺘﺷﺭ ﮏﯾ ﻪﺠﯿﺘﻧ

myJSON ﺖﺳﺍ ﺭﻭﺮﺳ ﻪﺑ ﻝﺎﺳﺭﺍ ﻩﺩﺎﻣﺁ ﻭ ﺖﺳﺍ ﻪﺘﺷﺭ ﮏﯾ ﻥﻮﻨﮐﺍ:

ﻝﺎﺜﻣ

var obj = {name:"John", age:30, city:"New York"};
var myJSON = JSON.stringify(obj);
document.getElementById("demo").innerHTML = myJSON;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>Create a JSON string from a JavaScript object.</h2>
<p id="demo"></p>

<script>
const obj = {name: "John", age: 30, city: "New York"};
const myJSON = JSON.stringify(obj);
document.getElementById("demo").innerHTML = myJSON;
</script>

</body>
</html>

.ﺪﯿﻧﺍﻮﺨﺑ ﺮﺘﺸﯿﺑ ﺎﻣ JSON ﺵﺯﻮﻣﺁ ﺭﺩ


Date.now()

Date.now() ﯽﻠﯿﻣ ﺩﺍﺪﻌﺗﻪﯿﻧﺎﺛﯽﻣﺮﺑ (ﻪﯾﻮﻧﺍﮊ ۱)

ﻝﺎﺜﻣ

var timInMSs = Date.now();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Date.now()</h2>

<p>Date.now() is new in ECMAScript 5 (2009):</p>

<p id="demo1"></p>
<p id="demo2"></p>

<script>
document.getElementById("demo1").innerHTML = Date.now();
var d = new Date();
document.getElementById("demo2").innerHTML = d.getTime();
</script>
</body>
</html>

Date.now() ﻪﮐ ﺍﺭ ﯼﺭﺎﮐ ﻥﺎﻤﻫ getTime() ﯽﺷ ﮏﯾ ﯼﻭﺭ

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ JS Dates ﺭﺩ


toISOSstring() ﺦﯾﺭﺎﺗ

:ﺪﻨﮐ ﯽﻣ ﻞﯾﺪﺒﺗ ﻪﺘﺷﺭ ﻪﺑ ISO ﺩﺭﺍﺪﻧﺎﺘﺳﺍ ﺐﻟﺎﻗ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﺍﺭ Date ﯽﺷ ﮏﯾ

ﻝﺎﺜﻣ

const d = new Date();
document.getElementById("demo").innerHTML = d.toISOString();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Dates</h1>
<h2>The toISOString() Method</h2>

<p>Convert a date to a string using the ISO standard:</p>
<p id="demo"></p>

<script>
const d = new Date();
document.getElementById("demo").innerHTML = d.toISOString();
</script>

</body>
</html>

toJSON() ﺦﯾﺭﺎﺗ

toJSON() ﯽﺷ ﮏﯾ Date ﺦﯾﺭﺎﺗ ﻥﺍﻮﻨﻋ ﻪﺑ ﻪﮐ ﺪﻨﮐ ﯽﻣ ﻞﯾﺪﺒﺗ ﯼ

:YYYY-MM-DDTHH:mm:ss.sssZ :ﺖﺳﺍ ISO-8601 ﺩﺭﺍﺪﻧﺎﺘﺳﺍ ﺪﻨﻧﺎﻣ JSON ﯼﺎﻫ ﺦﯾﺭﺎﺗ ﺖﻣﺮﻓ

ﻝﺎﺜﻣ

d = new Date();
document.getElementById("demo").innerHTML = d.toJSON();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Date.toJSON()</h2>

<p id="demo"></p>

<script>
d = new Date();
document.getElementById("demo").innerHTML = d.toJSON();
</script>

</body>
</html>

ﺹﺍﻮﺧ ﯼﺎﻫ ﻩﺪﻨﻨﮐ ﻢﯿﻈﻨﺗ ﻭ ﻥﺎﮔﺪﻧﺮﯿﮔ

ES5 ﯽﻣ ﻥﺎﮑﻣﺍ ﺎﻤﺷ ﻪﺑﺖﺳﺍ ﻢﯿﻈﻨﺗ ﺎﯾ ﺖﻓﺎﯾﺭﺩ ﻪﯿﺒﺷ ﻪﮐ ﺪﯿﻨﮐ ﻒﯾﺮﻌﺗ ﯼﻮﺤﻧ ﺎﺑ ﺍﺭ ﯽﺷ ﯼﺎﻫﺪﺘﻣ ﺎ

:ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ fullName ﻡﺎﻧ ﻪﺑ ﯽﮔﮋﯾﻭ ﮏﯾ ﯼﺍﺮﺑ ﻩﺪﻧﺮﯿﮔ ﮏﯾ ﻝﺎﺜﻣ ﻦﯾﺍ

ﻝﺎﺜﻣ

 // Create an object:
var person = {
  firstName: 
  "John",
  lastName : "Doe",
  get 
  fullName() {
    
  return this.firstName + " " + this.lastName;
  }
};
// Display data from the 
  object using a getter:
document.getElementById("demo").innerHTML = 
  person.fullName; 

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Getters and Setters</h2>

<p>Getters and setters allow you to get and set properties via methods.</p>

<p>This example creates a getter for a property called fullName.</p>

<p id="demo"></p>

<script>
// Create an object:
var person = {
  firstName: "John",
  lastName : "Doe",
  get fullName() {
    return this.firstName + " " + this.lastName;
  }
};
// Display data from the object using a getter:
document.getElementById("demo").innerHTML = person.fullName;
</script>

</body>
</html>

:ﺪﻨﮐﯽﻣ ﺩﺎﺠﯾﺍ ﻥﺎﺑﺯ ﯽﮔﮋﯾﻭ ﯼﺍﺮﺑ getter ﮏﯾ ﻭ setter

ﻝﺎﺜﻣ

 var person = {
  firstName: "John",
  
  lastName : "Doe",
  language : "NO",
  
  get lang() {
    return this.language;
  },
  set lang(value) {
    
  this.language = value;
  }
};
// Set an object 
  property using a setter:
person.lang = "en";
// Display data from the 
  object using a getter:
document.getElementById("demo").innerHTML = 
  person.lang;
 

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Getters and Setters</h2>

<p>Getters and setters allow you to get and set properties via methods.</p>

<p>This example creates a setter and a getter for the language property.</p>

<p id="demo"></p>

<script>
// Create an object:
var person = {
  firstName: "John",
  lastName : "Doe",
  language : "NO",
  get lang() {
    return this.language;
  },
  set lang(value) {
    this.language = value;
  }
};
// Set an object property using a setter:
person.lang = "en";
// Display data from the object using a getter:
document.getElementById("demo").innerHTML = person.lang;
</script>

</body>
</html>

:ﺪﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻥﺎﺑﺯ ﮒﺭﺰﺑ ﻑﻭﺮﺣ ﯼﺎﻫ ﯽﻧﺎﺳﺭ ﺯﻭﺭ ﻪﺑ ﻥﺩﺮﮐ ﻦﻤﯾﺍ ﯼﺍﺮﺑ ﻩﺪﻨﻨﮐ ﻢﯿﻈﻨﺗ ﮏﯾ ﺯﺍ ﻝﺎﺜﻣ

ﻝﺎﺜﻣ

 var person = {
  firstName: "John",
  
  lastName : "Doe",
  language : "NO",
  set lang(value) {
    
  this.language = value.toUpperCase();
  }
};
// Set an object 
  property using a setter:
person.lang = "en";
// Display data from the 
  object:
document.getElementById("demo").innerHTML = 
  person.language;
 

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Getters and Setters</h2>

<p>Getters and setters allow you to get and set properties via methods.</p>

<p>This example has a modified setter to secure upper case uppdates of language.</p>

<p id="demo"></p>

<script>
// Create an object:
var person = {
  firstName: "John",
  lastName : "Doe",
  language : "",
  set lang(value) {
     this.language = value.toUpperCase();
  }
};
// Set an object property using a setter:
person.lang = "en";
// Display data from the object:
document.getElementById("demo").innerHTML = person.language;
</script>

</body>
</html>

ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ JS Object Accessors ﺭﺩ ﺎﻫ Setter ﻭ Gettes ﻩﺭﺎﺑﺭﺩ


Object.defineProperty()

Object.defineProperty() ﺵﻭﺭ ﮏﯾ Object ﺭﺩ ﺪﯾﺪﺟ ES5 ﺖﺳ

ﺪﯿﻫﺩ ﺮﯿﯿﻐﺗ ﺍﺭ ﯽﮔﮋﯾﻭ ﮏﯾ ﺎﯾ/ﻭ ﺭﺍﺪﻘﻣ ﺎﯾ/ﻭ ﺪﯿﻨﮐ ﻒﯾﺮﻌﺗ ﺍﺭ ﯽﺷ ﯽﮔﮋﯾﻭ ﮏﯾ ﺪﻫﺩ ﯽﻣ ﻥﺎﮑﻣﺍ ﺎﻤﺷ ﻪﺑ

ﻝﺎﺜﻣ

 // Create an Object:
var person = {
  firstName: 
  "John",
  lastName : "Doe",
  language : "NO", 
};

  // Change a Property:
Object.defineProperty(person, "language", {
    
  value: "EN",
  writable : true,
  enumerable : true,
  configurable : true
});
// 
  Enumerate Properties
var txt = "";
for (var x in person) {
    
  txt += person[x] + "<br>";
}
document.getElementById("demo").innerHTML = 
  txt;
 

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>

<head>
<meta content="text/html; charset=iso-8859-2" http-equiv="Content-Type">
</head>

<body>

<h2>JavaScript defineProperty()</h2>

<p id="demo"></p>

<script>
// Create an Object:
var person = {
  firstName: "John",
  lastName : "Doe",
  language : "NO", 
};
// Change a Property:
Object.defineProperty(person, "language", {
  value: "EN",
  writable : true,
  enumerable : true,
  configurable : true
});
// Enumerate Properties
txt = "";
for (var x in person) {
  txt += person[x] + "<br>";
}
document.getElementById("demo").innerHTML = txt;
</script>

</body>
</html>

:ﺪﻨﮐ ﯽﻣ ﻥﺎﻬﻨﭘ enumeration ﺯﺍ ﺍﺭ ﻥﺎﺑﺯ ﯽﮔﮋﯾﻭ ﻪﮐ ﺕﻭﺎﻔﺗ ﻦﯾﺍ ﺎﺑ ،ﺖﺳﺍ ﺪﮐ ﻥﺎﻤﻫ ﯼﺪﻌﺑ ﻝﺎﺜﻣ

ﻝﺎﺜﻣ

 // Create an Object:
var person = {
  firstName: 
  "John",
  lastName : "Doe",
  language : "NO", 
};

  // Change a Property:
Object.defineProperty(person, "language", {
    
  value: "EN",
  writable : true,
  enumerable : false,
  configurable : true
});
// 
  Enumerate Properties
var txt = "";
for (var x in person) {
    
  txt += person[x] + "<br>";
}
document.getElementById("demo").innerHTML = 
  txt;
 

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript defineProperty()</h2>

<p id="demo"></p>

<script>
// Create an Object:
var person = {
  firstName: "John",
  lastName : "Doe",
  language : "NO", 
};
// Change a Property:
Object.defineProperty(person, "language", {
  value: "EN",
  writable : true,
  enumerable : false,
  configurable : true
});
// Enumerate Properties
txt = "";
for (var x in person) {
  txt += person[x] + "<br>";
}
document.getElementById("demo").innerHTML = txt;
</script>

</body>
</html>

:ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﻥﺎﺑﺯ ﮒﺭﺰﺑ ﻑﻭﺮﺣ ﯼﺎﻫ ﯽﻧﺎﺳﺭ ﺯﻭﺭ ﻪﺑ ﻥﺩﺮﮐ ﻦﻤﯾﺍ ﯼﺍﺮﺑ ﻩﺪﻧﺮﯿﮔ ﮏﯾ ﻭ ﻩﺪﻨﻨﮐ ﻢﯿﻈﻨﺗ

ﻝﺎﺜﻣ

 // Create an Object:
var person = {
  firstName: "John",
    lastName : 
  "Doe",
  language : "NO"
};
// Change a Property:
  Object.defineProperty(person, "language", {
  get : function() { return 
  language },
  set : function(value) { language = value.toUpperCase()}
});

  // Change Language
person.language = "en";
// Display Language
  document.getElementById("demo").innerHTML = person.language;

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript defineProperty()</h2>

<p id="demo"></p>

<script>
// Create an Object:
var person = {
  firstName: "John",
  lastName : "Doe",
  language : "NO"
};
// Change a Property:
Object.defineProperty(person, "language", {
  get : function() { return language },
  set : function(value) { language = value.toUpperCase()}
});
// Change language
person.language = "en";
// Display language
document.getElementById("demo").innerHTML = person.language;
</script>

</body>
</html>

E5 ﯽﺷ ﯼﺎﻫ ﺵﻭﺭ

ES5 ﺵﻭﺭ ﺯﺍ ﯼﺭﺎﯿﺴﺑﺩﺮﮐ ﻪﻓﺎﺿﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺑ ﺍﺭ ﺪﯾﺪﺟ ﯽﺷ ﯼﺎﻫ:

ءﺎﯿﺷﺍ ﺖﯾﺮﯾﺪﻣ

// Create object with an existing object as prototype
Object.create(parent, donor)

// Adding or changing an object property
Object.defineProperty(object, property, descriptor)

// Adding or changing object properties
Object.defineProperties(object, descriptors)

// Accessing Properties
Object.getOwnPropertyDescriptor(object, property)

// Returns all properties as an array
Object.getOwnPropertyNames(object)

// Accessing the prototype
Object.getPrototypeOf(object)

// Returns enumerable properties as an array
Object.keys(object)

ءﺎﯿﺷﺍ ﺯﺍ ﺖﻇﺎﻔﺣ

// Prevents adding properties to an object
Object.preventExtensions(object)

// Returns true if properties can be added to an object
Object.isExtensible(object)

// Prevents changes of object properties (not values)
Object.seal(object)

// Returns true if object is sealed
Object.isSealed(object)

// Prevents any changes to an object
Object.freeze(object)

// Returns true if object is frozen
Object.isFrozen(object)

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ Object ECMAScript5 ﺭﺩ


Bind() ﻊﺑﺎﺗ

.ﺩﺮﯿﮕﺑ ﺽﺮﻗ ﺮﮕﯾﺩ ﯽﺷ ﮏﯾ ﺯﺍ ﺍﺭ ﺪﺘﻣ ﮏﯾ ﺪﻧﺍﻮﺗ ﯽﻣ ﯽﺷ ﮏﯾ ،bind()

.ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ (ﻮﻀﻋ ﻭ ﺺﺨﺷ) ﯽﺷ 2 ﻝﺎﺜﻣ ﻦﯾﺍ

:ﺩﺮﯿﮔ ﯽﻣ ﺽﺮﻗ ﺺﺨﺷ ﯽﺷ ﺯﺍ ﺍﺭ fullname ﺪﺘﻣ ﻮﻀﻋ ﯽﺷ

ﻝﺎﺜﻣ

const person = {
  firstName:"John",
  lastName: "Doe",
    fullName: function () {
    return this.firstName + " " + this.lastName;
    }
}

const member = {
  firstName:"Hege",
  lastName: "Nilsen",
}

let fullName = person.fullName.bind(member);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Function bind()</h1>

<p>This example creates 2 objects (person and member).</p>
<p>The member object borrows the fullname method from person:</p> 

<p id="demo"></p>

<script>
const person = {
  firstName:"John",
  lastName: "Doe",
  fullName: function() {
    return this.firstName + " " + this.lastName;
  }
}

const member = {
  firstName:"Hege",
  lastName: "Nilsen",
}

let fullName = person.fullName.bind(member);

document.getElementById("demo").innerHTML = fullName();
</script>

</body>
</html>

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ()Function bind ﺭﺩ


ﺭﺍﺩ ﻪﻟﺎﺒﻧﺩ ﯼﺎﻫﺎﻣﺎﮐ

ES5 ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺩﻮﺟﻭ ﻪﯾﺍﺭﺁ ﻭ ﯽﺷ ﻒﯾﺭﺎﻌﺗ ﺭﺩ ﺭﺍﺩ ﻪﻟﺎﺒﻧﺩ ﯼﺎﻫﺎﻣﺎﮐ ﺎﺗ ﺪﻫﺩ ﯽﻣ ﻩﺯﺎﺟﺍ:

ﯽﺷ ﻝﺎﺜﻣ

person = {
  firstName: "John",
  lastName: "
Doe",
	age: 46,
}

ﻪﯾﺍﺭﺁ ﻝﺎﺜﻣ

points = [
  1,
  5,
  10,
  25,
  40,
  100,
];

!!!ﺭﺍﺪﺸﻫ

JSON ﺪﻫﺩ ﯽﻤﻧ ﺍﺭ ﯽﯾﺎﻬﺘﻧﺍ ﯼﺎﻫﺎﻣﺎﮐ ﻩﺯﺎﺟﺍ.

:JSON ءﺎﯿﺷﺍ

 //
  Allowed:
var person = '{"firstName":"John", "lastName":"Doe", 
  "age":46}'
JSON.parse(person)
// Not allowed:
var person = '{"firstName":"John", 
  "lastName":"Doe", "age":46,}'
JSON.parse(person)

:JSON ﯼﺎﻫ ﻪﯾﺍﺭﺁ

   //
    Allowed:
points = [40, 100, 1, 5, 25, 10]
// Not allowed:
points = 
    [40, 100, 1, 5, 25, 10,]

تمامی حقوق محفوظ است. © BasicIT.org • 2023-2024