ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ ﯼﺎﻫ ﺵﻭﺭ


فهرست مطالب

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

String length
String slice()
String substring()
String substr()
String replace()
String replaceAll()
String toUpperCase()
String toLowerCase()
String concat()
String trim()
String trimStart()
String trimEnd()
String padStart()
String padEnd()
String charAt()
String charCodeAt()
String split()

ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

.ﺖﺳﺍ ﻩﺪﺷ ﻩﺩﺍﺩ ﺶﺷﻮﭘ ﯼﺪﻌﺑ ﻞﺼﻓ ﺭﺩ ﯼﺍ ﻪﺘﺷﺭ ﻮﺠﺘﺴﺟ ﯼﺎﻫ ﺵﻭﺭ


ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ ﻝﻮﻃ

:ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ ﻝﻮﻃ length ﯽﮔﮋﯾﻭ

ﻝﺎﺜﻣ

let text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let length = text.length;

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>
<h2>The length Property</h2>

<p>The length of the string is:</p>
<p id="demo"></p>

<script>
let text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
document.getElementById("demo").innerHTML = text.length;
</script>

</body>
</html>


ﻪﺘﺷﺭ ﺕﺎﻌﻄﻗ ﺝﺍﺮﺨﺘﺳﺍ

:ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﻪﺘﺷﺭ ﮏﯾ ﺯﺍ ﯽﺸﺨﺑ ﺝﺍﺮﺨﺘﺳﺍ ﯼﺍﺮﺑ ﺵﻭﺭ 3

  • slice(start, end)
  • substring(start, end)
  • substr(start, length)

()ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ ﺵﺮﺑ

slice() ﻭ ﺪﻨﮐ ﯽﻣ ﺝﺍﺮﺨﺘﺳﺍ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ ﺯﺍ ﯽﺸﺨﺑ

.(ﺩﻮﺷ ﯽﻤﻧ ﻞﻣﺎﺷ ﻥﺎﯾﺎﭘ) ﻥﺎﯾﺎﭘ ﺖﯿﻌﻗﻮﻣ ﻭ ﻉﻭﺮﺷ ﺖﯿﻌﻗﻮﻣ :ﺩﺭﺍﺩ ﺮﺘﻣﺍﺭﺎﭘ 2 ﺵﻭﺭ ﻦﯾﺍ

ﻝﺎﺜﻣ

:ﺪﯿﻫﺩ ﺵﺮﺑ 13 ﺖﯿﻌﻗﻮﻣ ﻪﺑ 7 ﺖﯿﻌﻗﻮﻣ ﺯﺍ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ ﺯﺍ ﯽﺸﺨﺑ

let text = "Apple, Banana, Kiwi";
let part = text.slice(7, 13);

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

<!DOCTYPE html>
<html>
<body>

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

<p>The sliced (extracted) part of the string is:</p>
<p id="demo"></p>

<script>
let text = "Apple, Banana, Kiwi";
let part = text.slice(7,13);
document.getElementById("demo").innerHTML = part; 
</script>

</body>
</html>


ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

.ﺩﺭﺎﻤﺷ ﯽﻣ ﺮﻔﺻ ﺯﺍ ﺍﺭ ﺎﻫ ﺖﯿﻌﻗﻮﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ

.ﺖﺳﺍ 0 ﻝﻭﺍ ﺖﯿﻌﻗﻮﻣ

.ﺖﺳﺍ 1 ﻡﻭﺩ ﻩﺎﮕﯾﺎﺟ

ﺎﻫ ﻝﺎﺜﻣ

:ﺪﻫﺩ ﯽﻣ ﺵﺮﺑ ﺍﺭ ﻪﺘﺷﺭ ﻪﯿﻘﺑ ﺵﻭﺭ ،ﺪﯿﻨﮐ ﻑﺬﺣ ﺍﺭ ﻡﻭﺩ ﺮﺘﻣﺍﺭﺎﭘ ﺮﮔﺍ

let text = "Apple, Banana, Kiwi";
let part = text.slice(7);

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

<!DOCTYPE html>
<html>
<body>

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

<p>Extract a part of a string from position 7:</p>
<p id="demo"></p>

<script>
let text = "Apple, Banana, Kiwi";
let part = text.slice(7)
document.getElementById("demo").innerHTML = part;
</script>

</body>
</html>


:ﺩﻮﺷ ﯽﻣ ﺵﺭﺎﻤﺷ ﻪﺘﺷﺭ ﯼﺎﻬﺘﻧﺍ ﺯﺍ ﺖﯿﻌﻗﻮﻣ ،ﺪﺷﺎﺑ ﯽﻔﻨﻣ ﯼﺮﺘﻣﺍﺭﺎﭘ ﺮﮔﺍ

let text = "Apple, Banana, Kiwi";
let part = text.slice(-12);

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

<!DOCTYPE html>
<html>
<body>

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

<p>Extract a part of a string counting from the end:</p>
<p id="demo"></p>

<script>
let text = "Apple, Banana, Kiwi";
let part = text.slice(-12);
document.getElementById("demo").innerHTML = part;
</script>

</body>
</html>


:ﺪﻫﺩ ﯽﻣ ﺵﺮﺑ 6- ﺖﯿﻌﻗﻮﻣ ﻪﺑ 12- ﺖﯿﻌﻗﻮﻣ ﺯﺍ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ ﺯﺍ ﯽﺸﺨﺑ ﻝﺎﺜﻣ ﻦﯾﺍ

let text = "Apple, Banana, Kiwi";
let part = text.slice(-12, -6);

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

<!DOCTYPE html>
<html>
<body>

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

<p>Extract a part of a string and return the extracted parts in a new string:</p>

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

<script>
let text = "Apple, Banana, Kiwi";
let part = text.slice(-12,-6)
document.getElementById("demo").innerHTML = part;
</script>

</body>
</html>




()ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﻋﺮﻓ ﻪﺘﺷﺭ

substring() ﻪﺑﺎﺸﻣ slice() ﺖﺳﺍ.

ﺪﻧﻮﺷ ﯽﻣ ﻪﺘﻓﺮﮔ ﺮﻈﻧ ﺭﺩ ﭻﻨﯾﺍ 0 ﻥﺍﻮﻨﻋ ﻪﺑ 0 ﺯﺍ ﺮﺘﻤﮐ ﻥﺎﯾﺎﭘ ﻭ ﻉﻭﺮﺷ ﺮﯾﺩﺎﻘﻣ ﻪﮐ ﺖﺳﺍ ﻦﯾﺍ ﺕﻭﺎﻔﺗ

ﻝﺎﺜﻣ

let str = "Apple, Banana, Kiwi";
let part = str.substring(7, 13);

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String Methods</h1>
<p>The substring() method extract a part of a string and returns the extracted parts in a new string:</p>

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

<script>
let str = "Apple, Banana, Kiwi";
document.getElementById("demo").innerHTML = str.substring(7,13);
</script>

</body>
</html>

.ﺪﻫﺩ ﯽﻣ ﺵﺮﺑ ﺍﺭ ﺎﻫ ﺖﻤﺴﻗ ﻪﯿﻘﺑ substring() ،ﺪﯿﻨﮐ ﻑﺬﺣ ﺍﺭ ﻡﻭﺩ ﺮﺘﻣﺍﺭﺎﭘ ﺮﮔﺍ


substr() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ

substr() ﻪﯿﺒﺷ slice() ﺖﺳﺍ.

ﺖﺳﺍ ﻦﯾﺍ ﺕﻭﺎﻔﺗ

ﻝﺎﺜﻣ

let str = "Apple, Banana, Kiwi";
let part = str.substr(7, 6);

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String Methods</h1>
<p>The substr() method extract a part of a string
and returns the extracted parts in a new string:</p>

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

<script>
let str = "Apple, Banana, Kiwi";
document.getElementById("demo").innerHTML = str.substr(7,6);
</script>

</body>
</html>


.ﺪﻫﺩ ﯽﻣ ﺵﺮﺑ ﺍﺭ ﺩﺭﺍﻮﻣ ﻪﯿﻘﺑ substr() ،ﺪﯿﻨﮐ ﻑﺬﺣ ﺍﺭ ﻡﻭﺩ ﺮﺘﻣﺍﺭﺎﭘ ﺮﮔﺍ

ﻝﺎﺜﻣ

let str = "Apple, Banana, Kiwi";
let part = str.substr(7);

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String Methods</h1>
<p>The substr() method extract a part of a string and returns the extracted parts in a new string:</p>

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

<script>
let str = "Apple, Banana, Kiwi";
document.getElementById("demo").innerHTML = str.substr(7);
</script>

</body>
</html>


ﺩﻮﺷ ﯽﻣ ﻪﺒﺳﺎﺤﻣ ﻥﺁ ﯼﺎﻬﺘﻧﺍ ﺯﺍ ﺖﯿﻌﻗﻮﻣ ،ﺪﺷﺎﺑ ﯽﻔﻨﻣ ﻝﻭﺍ ﺮﺘﻣﺍﺭﺎﭘ ﺮﮔﺍ

ﻝﺎﺜﻣ

let str = "Apple, Banana, Kiwi";
let part = str.substr(-4);

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String Methods</h1>
<p>The substr() method extract a part of a string and returns the extracted parts in a new string:</p>

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

<script>
let str = "Apple, Banana, Kiwi";
document.getElementById("demo").innerHTML = str.substr(-4);
</script>

</body>
</html>



ﻪﺘﺷﺭ ﯼﺍﻮﺘﺤﻣ ﯽﻨﯾﺰﮕﯾﺎﺟ

.ﺪﻨﮐ ﯽﻣ ﻦﯾﺰﮕﯾﺎﺟ ﯼﺮﮕﯾﺩ ﺭﺍﺪﻘﻣ ﺎﺑ ﺍﺭ ﻩﺪﺷ ﺺﺨﺸﻣ ﺭﺍﺪﻘﻣ ﮏﯾ replace() ﺵﻭﺭ

ﻝﺎﺜﻣ

let text = "Please visit Microsoft!";
let newText = text.replace("Microsoft", "W3Schools");

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

<!DOCTYPE html>
<html>

<body>

<h1>JavaScript String Methods</h1>
<p>Replace &quot;Microsoft&quot; with &quot;W3Schools&quot; in the paragraph below:</p>

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

<p id="demo">Please visit Microsoft!</p>

<script>
function myFunction() {
  let text = document.getElementById("demo").innerHTML;
  document.getElementById("demo").innerHTML =
  text.replace("Microsoft","W3Schools");
}
</script>

</body>
</html>


ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

.ﺪﻫﺩ ﯽﻤﻧ ﺮﯿﯿﻐﺗ ﺩﻮﺷ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﻥﺁ ﯼﻭﺭ ﻪﮐ ﺍﺭ ﯼﺍ ﻪﺘﺷﺭ replace() ﺪﺘﻣ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺪﯾﺪﺟ ﻪﺘﺷﺭ ﮏﯾ replace() ﺪﺘﻣ

ﺩﻮﺷ ﯽﻣ ﺖﻘﺑﺎﻄﻣ ﻦﯿﻟﻭﺍ ﻂﻘﻓ ﻦﯾﺰﮕﯾﺎﺟ replace() ﺵﻭﺭ

.ﺪﯿﻨﯿﺒﺑ ﺍﺭ ﺮﯾﺯ ﯼﺎﻫ ﻪﻧﻮﻤﻧ .ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ g/ ﻢﭼﺮﭘ ﻪﻋﻮﻤﺠﻣ ﺎﺑ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ ﺯﺍ ،ﺪﯿﻨﮐ ﻦﯾﺰﮕﯾﺎﺟ ﺍﺭ ﺎﻫ ﺖﻘﺑﺎﻄﻣ ﻪﻤﻫ ﺪﯿﻫﺍﻮﺧ ﯽﻣ ﺮﮔ

:ﺩﻮﺷ ﯽﻣ ﺖﻘﺑﺎﻄﻣ ﻦﯿﻟﻭﺍ ﻂﻘﻓ ﻦﯾﺰﮕﯾﺎﺟ replace() ﺵﻭﺭ ،ﺽﺮﻓ ﺶﯿﭘ ﺭﻮﻃ ﻪﺑ

ﻝﺎﺜﻣ

let text = "Please visit Microsoft and Microsoft!";
let newText = text.replace("Microsoft", "W3Schools");

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String Methods</h1>
<p>Replace "Microsoft" with "W3Schools" in the paragraph below:</p>

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

<p id="demo">Please visit Microsoft and Microsoft!</p>

<script>
function myFunction() {
  let text = document.getElementById("demo").innerHTML; 
  document.getElementById("demo").innerHTML =
  text.replace("Microsoft","W3Schools");
}
</script>

</body>
</html>


ﺎﺑ) ﺖﻓﺎﺳﻭﺮﮑﯾﺎﻣ ﻦﺘﺷﻮﻧ .ﺖﺳﺍ ﺱﺎﺴﺣ ﮒﺭﺰﺑ ﻭ ﮏﭼﻮﮐ ﻑﻭﺮﺣ ﻪﺑ replace() ﺵﻭﺭ ،ﺽﺮﻓ ﺶﯿﭘ ﺭﻮﻃ ﻪﺑ

ﻝﺎﺜﻣ

let text = "Please visit Microsoft!";
let newText = text.replace("MICROSOFT", "W3Schools");

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String Methods</h1>
<p>Try to replace "Microsoft" with "W3Schools" in the paragraph below:</p>

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

<p id="demo">Please visit Microsoft!</p>

<script>
function myFunction() {
  let text = document.getElementById("demo").innerHTML; 
  document.getElementById("demo").innerHTML =
  text.replace("MICROSOFT","W3Schools");
}
</script>

<p>The replace() method is case sensitive. MICROSOFT (with upper-case) will not be replaced.</p>

</body>
</html>

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ (ﺱﺎﺴﺣ ﺮﯿﻏ) /i ﻢﭼﺮﭘ ﺎﺑ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ ﺯﺍ ،ﮏﭼﻮﮐ ﻭ ﮒﺭﺰﺑ ﻑ

ﻝﺎﺜﻣ

let text = "Please visit Microsoft!";
let newText = text.replace(/MICROSOFT/i, "W3Schools");

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String Methods</h1>
<p>Replace "Microsoft" with "W3Schools" in the paragraph below:</p>

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

<p id="demo">Please visit Microsoft!</p>

<script>
function myFunction() {
  let text = document.getElementById("demo").innerHTML; 
  document.getElementById("demo").innerHTML =
  text.replace(/MICROSOFT/i,"W3Schools");
}
</script>

</body>
</html>


ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

.ﺪﻧﻮﺷ ﯽﻣ ﻪﺘﺷﻮﻧ ﻝﻮﻗ ﻞﻘﻧ ﻥﻭﺪﺑ ﻢﻈﻨﻣ ﺕﺍﺭﺎﺒﻋ

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ (ﯽﻧﺎﻬﺟ ﻖﺑﺎﻄﺗ) /g ﻢﭼﺮﭘ ﺎﺑ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ ﺯﺍ ،ﻖﺒﻄﻨﻣ ﺩﺭﺍﻮ

ﻝﺎﺜﻣ

let text = "Please visit Microsoft and Microsoft!";
let newText = text.replace(/Microsoft/g, "W3Schools");

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String Methods</h1>
<p>Replace all occurrences of "Microsoft" with "W3Schools" in the paragraph below:</p>

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

<p id="demo">Please visit Microsoft and Microsoft!</p>

<script>
function myFunction() {
  let text = document.getElementById("demo").innerHTML; 
  document.getElementById("demo").innerHTML =
  text.replace(/Microsoft/g,"W3Schools");
}
</script>

</body>
</html>


ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

ﺖﺧﻮﻣﺁ ﺪﯿﻫﺍﻮﺧ ﻢﻈﻨﻣ ﺕﺍﺭﺎﺒﻋ ﺩﺭﻮﻣ ﺭﺩ ﯼﺮﺘﺸﯿﺑ ﯼﺎﻫﺰﯿﭼ JavaScript Regular ﺶﺨﺑ ﺭﺩ


()ReplaceAll ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ

:ﺩﺮﮐ ﯽﻓﺮﻌﻣ ﺍﺭ replaceAll() ﯼﺍ ﻪﺘﺷﺭ ﺵﻭﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ،2021 ﻝﺎﺳ ﺭﺩ

ﻝﺎﺜﻣ

text = text.replaceAll("Cats","Dogs");
text = text.replaceAll("cats","dogs");

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The replaceAll() Method</h2>

<p>ES2021 intoduced the string method replaceAll().</p>

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

<script>
let text = "I love cats. Cats are very easy to love. Cats are very popular."
text = text.replaceAll("Cats","Dogs");
text = text.replaceAll("cats","dogs");

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

</body>
</html>

ﺪﻫﺩ ﯽﻣ ﻥﺎﮑﻣﺍ ﺎﻤﺷ ﻪﺑ replaceAll() ﺵﻭﺭ

ﺕﺭﻮﺻ ﻦﯾﺍ ﺮﯿﻏ ﺭﺩ ،ﺩﻮﺷ ﻢﯿﻈﻨﺗ ﺪﯾﺎﺑ (g) ﯽﻧﺎﻬﺟ ﻢﭼﺮﭘ ،ﺖﺳﺍ ﻢﻈﻨﻣ ﺕﺭﺎﺒﻋ ﮏﯾ ﺮﺘﻣﺍﺭﺎﭘ ﺮﮔﺍ

ﻝﺎﺜﻣ

text = text.replaceAll(/Cats/g,"Dogs");
text = text.replaceAll(/cats/g,"dogs");

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The replaceAll() Method</h2>

<p>ES2021 intoduced the string method replaceAll().</p>

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

<script>
let text = "I love cats. Cats are very easy to love. Cats are very popular";
text = text.replaceAll(/Cats/g,"Dogs");
text = text.replaceAll(/cats/g,"dogs");

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

</body>
</html>

ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

replaceAll() ﯽﮔﮋﯾﻭ ﮏﯾ ES2021 ﺖﺳﺍ.

replaceAll() ﺪﻨﮐ ﯽﻤﻧ ﺭﺎﮐ ﺭﺭﻮﻠﭙﺴﮐﺍ ﺖﻧﺮﺘﻨﯾﺍ ﺭﺩ.


ﮏﭼﻮﮐ ﻭ ﮒﺭﺰﺑ ﻑﻭﺮﺣ ﻪﺑ ﻞﯾﺪﺒﺗ

:ﺩﻮﺷ ﯽﻣ ﻞﯾﺪﺒﺗ ﮒﺭﺰﺑ ﻑﻭﺮﺣ ﻪﺑ toUpperCase() ﺎﺑ ﻪﺘﺷﺭ ﮏﯾ

:ﺩﻮﺷ ﯽﻣ ﻞﯾﺪﺒﺗ ﮏﭼﻮﮐ ﻑﻭﺮﺣ ﻪﺑ toLowerCase() ﺎﺑ ﻪﺘﺷﺭ ﮏﯾ


()toUpperCase ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ

ﻝﺎﺜﻣ

let text1 = "Hello World!";
let text2 = text1.toUpperCase();

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String Methods</h1>
<p>Convert string to upper case:</p>

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

<p id="demo">Hello World!</p>

<script>
function myFunction() {
  let text = document.getElementById("demo").innerHTML;
  document.getElementById("demo").innerHTML =
  text.toUpperCase();
}
</script>

</body>
</html>

()toLowerCase ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ

ﻝﺎﺜﻣ

let text1 = "Hello World!";       // String
let text2 = text1.toLowerCase();  // text2 is text1 
converted to lower

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String Methods</h1>
<p>Convert string to lower case:</p>

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

<p id="demo">Hello World!</p>

<script>
function myFunction() {
  let text = document.getElementById("demo").innerHTML;
  document.getElementById("demo").innerHTML =
  text.toLowerCase();
}
</script>

</body>
</html>

()concat ﻪﺘﺷﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ

concat() ﯽﻣ ﺍﺭ ﻪﺘﺷﺭ ﺪﻨﭼ ﺎﯾ ﻭﺩﺩﺪﻧﻮﯿﭘ:

ﻝﺎﺜﻣ

let text1 = "Hello";
let text2 = "World";
let text3 = text1.concat(" ", text2);

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String</h1>
<h2>The concat() Method</h2>

<p>The concat() method joins two or more strings:</p>

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

<script>
let text1 = "Hello";
let text2 = "World!";
let text3 = text1.concat(" ",text2);
document.getElementById("demo").innerHTML = text3;
</script>

</body>
</html>


.ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺱﻼﭘ ﺮﮕﻠﻤﻋ ﯼﺎﺟ ﻪﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ concat() ﺵﻭﺭ

ﻝﺎﺜﻣ

text = "Hello" + " " + "World!";
text = "Hello".concat(" ", "World!");

ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

.ﺪﻨﻫﺩ ﯽﻤﻧ ﺮﯿﯿﻐﺗ ﺍﺭ ﯽﻠﺻﺍ ﻪﺘﺷﺭ ﺎﻬﻧﺁ .ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﺪﯾﺪﺟ ﻪﺘﺷﺭ ﮏﯾ ﯼﺍ ﻪﺘﺷﺭ ﯼﺎﻫﺪﺘﻣ ﻡﺎﻤﺗ

:ﺖﻔﮔ ﯽﻤﺳﺭ ﺭﻮﻃ ﻪﺑ

.ﺩﻮﺷ ﯽﻣ ﻦﯾﺰﮕﯾﺎﺟ ﻂﻘﻓ ،ﺩﺍﺩ ﺮﯿﯿﻐﺗ ﻥﺍﻮﺗ ﯽﻤﻧ ﺍﺭ ﺎﻫ ﻪﺘﺷﺭ :ﺪﻨﺘﺴﻫ ﺮﯾﺬﭘﺎﻧ ﺮﯿﯿﻐﺗ ﺎﻫ ﻪﺘﺷﺭ


()ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ ﺵﺮﺑ

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

ﻝﺎﺜﻣ

let text1 = "      Hello World!      ";
let text2 = text1.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>

trimStart() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ

ECMAScript 2019 ﺵﻭﺭ String trimStart() ﺩﺮﮐ ﻪﻓﺎﺿﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺑ ﺍﺭ.

ﻝﺎﺜﻣ

let text1 = "     Hello World!     ";
let text2 = text1.trimStart();

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

<!DOCTYPE html>
<html>
<body>

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

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

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

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

</body>
</html>

:ﺩﻮﺷﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﻤﻫ ﺭﺩ 2020 ﻪﯾﻮﻧﺍﮊ ﺯﺍ trimStart()

Chrome 66 Edge 79 Firefox 61 Safari 12 Opera 50
Apr 2018 Jan 2020 Jun 2018 Sep 2018 May 2018

trimEnd() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ

ECMAScript 2019 ﻪﺘﺷﺭ ﺵﻭﺭ trimEnd() ﺩﺮﮐ ﻪﻓﺎﺿﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺑ ﺍﺭ.

ﻝﺎﺜﻣ

let text1 = "     Hello World!     ";
let text2 = text1.trimEnd();

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

<!DOCTYPE html>
<html>
<body>

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

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

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

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

</body>
</html>

:ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﻤﻫ ﺭﺩ 2020 ﻪﯾﻮﻧﺍﮊ ﺯﺍ trimEnd() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ

Chrome 66 Edge 79 Firefox 61 Safari 12 Opera 50
Apr 2018 Jan 2020 Jun 2018 Sep 2018 May 2018

ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ ﯼﺪﻨﺑ ﻪﯾﻻ

ECMAScript 2017 ﺩﺮﮐ ﻪﻓﺎﺿﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺑ ﺍﺭ ﺪﯾﺪﺟ ﻪﺘﺷﺭ ﺵﻭﺭ ﻭﺩ: padStart()


padStart() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ

.ﺪﻨﮐ ﯽﻣ ﺭﺍﺪﯾﺪﭘ ﺍﺪﺘﺑﺍ ﺯﺍ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ padStart() ﺵﻭﺭ

.ﺪﺳﺮﺑ ﯽﻨﯿﻌﻣ ﻝﻮﻃ ﻪﺑ ﺎﺗ ﺪﻧﺎﺷﻮﭘﯽﻣ (ﺭﺎﺑ ﺪﻨﭼ) ﺮﮕﯾﺩ ﻪﺘﺷﺭ ﮏﯾ ﺎﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ

ﺎﻫ ﻝﺎﺜﻣ

:ﺪﺳﺮﺑ 4 ﻝﻮﻃ ﻪﺑ ﺎﺗ ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ "0" ﺎﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ

let text = "5";
let padded = text.padStart(4,"0");

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

<!DOCTYPE html>
<html>
<body>

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

<p>The padStart() method pads a string from the start.</p>
<p>It pads the string with another string (multiple times) until it reaches a given length.</p>

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

<script>
let text = "5";
text = text.padStart(4,"0");

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

</body>
</html>

:ﺪﺳﺮﺑ 4 ﻝﻮﻃ ﻪﺑ ﺎﺗ ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ "x" ﺎﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ

let text = "5";
let padded = text.padStart(4,"x");

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

<!DOCTYPE html>
<html>
<body>

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

<p>The padStart() method pads a string from the start.</p>
<p>It pads the string with another string (multiple times) until it reaches a given length.</p>

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

<script>
let text = "5";
document.getElementById("demo").innerHTML = text.padStart(4,"x");
</script>

</body>
</html>

ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

.ﺖﺳﺍ ﯼﺍ ﻪﺘﺷﺭ ﺵﻭﺭ ﮏﯾ padStart() ﺪﺘﻣ

.ﺪﯿﻨﮐ ﻞﯾﺪﺒﺗ ﻪﺘﺷﺭ ﻪﺑ ﺍﺭ ﺩﺪﻋ ﺍﺪﺘﺑﺍ ،ﺩﺪﻋ ﮏﯾ ﻥﺩﺮﮐ ﻪﻓﺎﺿﺍ ﯼﺍﺮﺑ

.ﺪﯿﻨﯿﺒﺑ ﺍﺭ ﺮﯾﺯ ﻝﺎﺜﻣ

ﻝﺎﺜﻣ

let numb = 5;
let text = numb.toString();
let padded = text.padStart(4,"0");

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

<!DOCTYPE html>
<html>
<body>

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

<p>The padStart() method pads a string from the start.</p>
<p>It pads the string with another string (multiple times) until it reaches a given length.</p>

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

<script>
let numb = 5;
let text = numb.toString();
document.getElementById("demo").innerHTML = text.padStart(4,0);
</script>

</body>
</html>

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

padStart() ﯽﮔﮋﯾﻭ ﮏﯾ ECMAScript 2017 ﺖﺳﺍ.

:ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻡﺎﻤﺗ ﺭﺩ

Chrome Edge Firefox Safari Opera
Yes Yes Yes Yes Yes

padStart() ﯽﻤﻧ ﯽﻧﺎﺒﯿﺘﺸﭘ ﺭﺭﻮﻠﭙﺴﮐﺍ ﺖﻧﺮﺘﻨﯾﺍ ﺭﺩﺩﻮﺷ.


padEnd ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ()

.ﺪﻨﮐ ﯽﻣ ﺭﺍﺪﯾﺪﭘ ﺎﻬﺘﻧﺍ ﺯﺍ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ padEnd() ﺵﻭﺭ

.ﺪﺳﺮﺑ ﯽﻨﯿﻌﻣ ﻝﻮﻃ ﻪﺑ ﺎﺗ ﺪﻧﺎﺷﻮﭘﯽﻣ (ﺭﺎﺑ ﺪﻨﭼ) ﺮﮕﯾﺩ ﻪﺘﺷﺭ ﮏﯾ ﺎﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ

ﺎﻫ ﻝﺎﺜﻣ

let text = "5";
let padded = text.padEnd(4,"0");

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

<!DOCTYPE html>
<html>
<body>

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

<p>The padEnd() method pads a string at the end.</p>
<p>It pads the string with another string (multiple times) until it reaches a given length.</p>

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

<script>
let text = "5";
text = text.padEnd(4,"0");

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

</body>
</html>
let text = "5";
let padded = text.padEnd(4,"x");

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

<!DOCTYPE html>
<html>
<body>

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

<p>The padEnd() method pads a string at the end.</p>
<p>It pads the string with another string (multiple times) until it reaches a given length.</p>

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

<script>
let text = "5";
document.getElementById("demo").innerHTML = text.padEnd(4,"x");
</script>

</body>
</html>

ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

.ﺖﺳﺍ ﯼﺍ ﻪﺘﺷﺭ ﺵﻭﺭ ﮏﯾ padEnd() ﺪﺘﻣ

.ﺪﯿﻨﮐ ﻞﯾﺪﺒﺗ ﻪﺘﺷﺭ ﻪﺑ ﺍﺭ ﺩﺪﻋ ﺍﺪﺘﺑﺍ ،ﺩﺪﻋ ﮏﯾ ﻥﺩﺮﮐ ﻪﻓﺎﺿﺍ ﯼﺍﺮﺑ

.ﺪﯿﻨﯿﺒﺑ ﺍﺭ ﺮﯾﺯ ﻝﺎﺜﻣ

ﻝﺎﺜﻣ

let numb = 5;
let text = numb.toString();
let padded = text.padEnd(4,"0");

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

<!DOCTYPE html>
<html>
<body>

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

<p>The padEnd() method pads a string at the end.</p>
<p>It pads the string with another string (multiple times) until it reaches a given length.</p>

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

<script>
let numb = 5;
let text = numb.toString();
document.getElementById("demo").innerHTML = text.padEnd(4,"x");
</script>

</body>
</html>

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

padEnd() ﯽﮔﮋﯾﻭ ﮏﯾ ECMAScript 2017 ﺖﺳﺍ.

:ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻡﺎﻤﺗ ﺭﺩ

Chrome Edge Firefox Safari Opera
Yes Yes Yes Yes Yes

padEnd() ﺩﻮﺷ ﯽﻤﻧ ﯽﻧﺎﺒﯿﺘﺸﭘ ﺭﺭﻮﻠﭙﺴﮐﺍ ﺖﻧﺮﺘﻨﯾﺍ ﺭﺩ.


ﯼﺍ ﻪﺘﺷﺭ ﯼﺎﻫﺮﺘﮐﺍﺭﺎﮐ ﺝﺍﺮﺨﺘﺳﺍ

:ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﻪﺘﺷﺭ ﯼﺎﻫﺮﺘﮐﺍﺭﺎﮐ ﺝﺍﺮﺨﺘﺳﺍ ﯼﺍﺮﺑ ﺵﻭﺭ 3

  • charAt(position)

  • charCodeAt(position)

  • [ ] ﮏﻠﻣ ﻪﺑ ﯽﺳﺮﺘﺳﺩ


charAt() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ

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

ﻝﺎﺜﻣ

let text = "HELLO WORLD";
let char = text.charAt(0);

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String</h1>
<h2>The charAt() Method</h2>

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

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

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

</body>
</html>


()charCodeAt ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﺮﺘﮐﺍﺭﺎﮐ ﺪﮑﯿﻧﻮﯾ charCodeAt() ﺵﻭﺭ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ (65535 ﻭ 0 ﻦﯿﺑ ﺢﯿﺤﺻ ﺩﺪﻋ ﮏﯾ) UTF-16 ﺪﮐ ﮏﯾ ﺵﻭﺭ ﻦﯾﺍ

ﻝﺎﺜﻣ

let text = "HELLO WORLD";
let char = text.charCodeAt(0);

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String</h1>
<h2>The charCodeAt() Method</h2>

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

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

<script>
let text = "HELLO WORLD";
document.getElementById("demo").innerHTML = text.charCodeAt(0);
</script>

</body>
</html>


ﻝﺍﻮﻣﺍ ﻪﺑ ﯽﺳﺮﺘﺳﺩ

ECMAScript 5 (2009) ﺪﻫﺩ ﯽﻣ ﺎﻫ ﻪﺘﺷﺭ ﺭﺩ ﺍﺭ [ ] ﯽﮔﮋﯾﻭ ﻪﺑ ﯽﺳﺮﺘﺳﺩ ﻩﺯﺎﺟﺍ:

ﻝﺎﺜﻣ

let text = "HELLO WORLD";
let char = text[0];

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>
<p>Property access on strings:</p>

<p>The first character in the string is:</p>
<p id="demo"></p>

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

ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

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

  • (ﺖﺴﯿﻧ ﺭﻮﻄﻨﯾﺍ ﺎﻣﺍ) ﺪﻨﮐ ﯽﻣ ﻪﯾﺍﺭﺁ ﻪﯿﺒﺷ ﺍﺭ ﺎﻫ ﻪﺘﺷﺭ

  • .ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﯽﻟﺎﺧ ﻪﺘﺷﺭ ﮏﯾ()charAt ﻪﮐ ﯽﻟﺎﺣ ﺭﺩ ،ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ [ ] ،ﺪﺸﻧ ﺍﺪﯿﭘ ﯼﺮﺘﮐﺍﺭﺎﮐ ﭻﯿﻫ ﺮﮔﺍ

  • (!ﺪﻨﮐ ﯽﻤﻧ ﺭﺎﮐ ﺎﻣﺍ) ﺪﻫﺩ ﯽﻤﻧ ﯽﯾﺎﻄﺧ "str[0]="A .ﺩﻮﺷ ﯽﻣ ﻩﺪﻧﺍﻮﺧ ﻂﻘﻓ

ﻝﺎﺜﻣ

let text = "HELLO WORLD";
text[0] = "A";    // Gives no error, but does not work

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>
<p>Property acces on strings are read only:</p>

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

<script>
let text = "HELLO WORLD";

text[0] = "A";  // Does not work

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

</body>
</html>

ﻪﯾﺍﺭﺁ ﻪﺑ ﻪﺘﺷﺭ ﻞﯾﺪﺒﺗ

.ﺪﯿﻨﮐ ﻞﯾﺪﺒﺗ ﻪﯾﺍﺭﺁ ﻪﺑ ﺍﺭ ﻥﺁ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ،ﺪﯿﻨﮐ ﺭﺎﮐ ﻪﯾﺍﺭﺁ ﻥﺍﻮﻨﻋ ﻪﺑ ﯼﺍ ﻪﺘﺷﺭ ﺎﺑ ﺪﯿﻫﺍﻮﺧ ﯽﻣ ﺮﮔﺍ

split() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ

:ﺩﺮﮐ ﻞﯾﺪﺒﺗ ﻪﯾﺍﺭﺁ ﻪﺑ split() ﺵﻭﺭ ﺎﺑ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ

ﻝﺎﺜﻣ

text.split(",")    // Split on commas
text.split(" ")    // Split on spaces
text.split("|")    // Split on pipe

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String Methods</h1>
<p>Display the first array element, after a string split:</p>

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

<script>
let text = "a,b,c,d,e,f";
const myArray = text.split(",");
document.getElementById("demo").innerHTML = myArray[0];
</script>

</body>
</html>


ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﻪﺘﺷﺭ ﻞﮐ ﻞﻣﺎﺷ ﯽﺘﺸﮔﺮﺑ ﻪﯾﺍﺭﺁ ،ﺩﻮﺷ ﻑﺬﺣ ﻩﺪﻨﻨﮐﺍﺪﺟ ﺮﮔﺍ

ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﮏﺗ ﺯﺍ ﯼﺍ ﻪﯾﺍﺭﺁ ﯽﺘﺸﮔﺮﺑ ﻪﯾﺍﺭﺁ ،ﺪﺷﺎﺑ "" ﻩﺪﻨﻨﮐﺍﺪﺟ ﺮﮔﺍ

ﻝﺎﺜﻣ

text.split("")

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

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript String Methods</h1>
<h2>The split().Method</h2>

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

<script>
let text = "Hello";
const myArr = text.split("");

text = "";
for (let i = 0; i < myArr.length; i++) {
  text += myArr[i] + "<br>"
}
document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>


ﻪﺘﺷﺭ ﻞﻣﺎﮐ ﻊﺟﺮﻣ

:ﺪﯾﻭﺮﺑ ﺎﻣ ﺱﺭﺩﺁ ﻪﺑ ،ﻪﺘﺷﺭ ﻞﻣﺎﮐ ﻊﺟﺮﻣ ﮏﯾ ﯼﺍﺮﺑ

.ﺪﯿﻨﮐ ﻞﻣﺎﮐ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ ﻊﺟﺮﻣ

.ﺖﺳﺍ ﻪﺘﺷﺭ ﯼﺎﻫ ﺵﻭﺭ ﻭ ﺎﻫ ﯽﮔﮋﯾﻭ ﻡﺎﻤﺗ ﺯﺍ ﯽﯾﺎﻫ ﻪﻧﻮﻤﻧ ﻭ ﺕﺎﺤﯿﺿﻮﺗ ﯼﻭﺎﺣ ﻊﺟﺮﻣ

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