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()
ﻪﯿﺒﺷ 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 "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>
</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()
ﯼﺍ ﻪﺘﺷﺭ ﺵﻭﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ،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()
ﺎﺑ ﻪﺘﺷﺭ ﮏﯾ
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>
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()
ﯽﻣ ﺍﺭ ﻪﺘﺷﺭ ﺪﻨﭼ ﺎﯾ ﻭﺩﺩﺪﻧﻮﯿﭘ:
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>
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 ﻪﯾﻮﻧﺍﮊ ﺯﺍ ECMAScript 2019 ﻪﺘﺷﺭ ﺵﻭﺭ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻪﻤﻫ ﺭﺩ 2020 ﻪﯾﻮﻧﺍﮊ ﺯﺍ ECMAScript 2017 ﺩﺮﮐ ﻪﻓﺎﺿﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺑ ﺍﺭ ﺪﯾﺪﺟ ﻪﺘﺷﺭ ﺵﻭﺭ ﻭﺩ: .ﺪﻨﮐ ﯽﻣ ﺭﺍﺪﯾﺪﭘ ﺍﺪﺘﺑﺍ ﺯﺍ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ .ﺪﺳﺮﺑ ﯽﻨﯿﻌﻣ ﻝﻮﻃ ﻪﺑ ﺎﺗ ﺪﻧﺎﺷﻮﭘﯽﻣ (ﺭﺎﺑ ﺪﻨﭼ) ﺮﮕﯾﺩ ﻪﺘﺷﺭ ﮏﯾ ﺎﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ :ﺪﺳﺮﺑ 4 ﻝﻮﻃ ﻪﺑ ﺎﺗ ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ "0" ﺎﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺪﺳﺮﺑ 4 ﻝﻮﻃ ﻪﺑ ﺎﺗ ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ "x" ﺎﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺖﺳﺍ ﯼﺍ ﻪﺘﺷﺭ ﺵﻭﺭ ﮏﯾ .ﺪﯿﻨﮐ ﻞﯾﺪﺒﺗ ﻪﺘﺷﺭ ﻪﺑ ﺍﺭ ﺩﺪﻋ ﺍﺪﺘﺑﺍ ،ﺩﺪﻋ ﮏﯾ ﻥﺩﺮﮐ ﻪﻓﺎﺿﺍ ﯼﺍﺮﺑ .ﺪﯿﻨﯿﺒﺑ ﺍﺭ ﺮﯾﺯ ﻝﺎﺜﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻡﺎﻤﺗ ﺭﺩ .ﺪﻨﮐ ﯽﻣ ﺭﺍﺪﯾﺪﭘ ﺎﻬﺘﻧﺍ ﺯﺍ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ .ﺪﺳﺮﺑ ﯽﻨﯿﻌﻣ ﻝﻮﻃ ﻪﺑ ﺎﺗ ﺪﻧﺎﺷﻮﭘﯽﻣ (ﺭﺎﺑ ﺪﻨﭼ) ﺮﮕﯾﺩ ﻪﺘﺷﺭ ﮏﯾ ﺎﺑ ﺍﺭ ﻪﺘﺷﺭ ﮏﯾ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺖﺳﺍ ﯼﺍ ﻪﺘﺷﺭ ﺵﻭﺭ ﮏﯾ .ﺪﯿﻨﮐ ﻞﯾﺪﺒﺗ ﻪﺘﺷﺭ ﻪﺑ ﺍﺭ ﺩﺪﻋ ﺍﺪﺘﺑﺍ ،ﺩﺪﻋ ﮏﯾ ﻥﺩﺮﮐ ﻪﻓﺎﺿﺍ ﯼﺍﺮﺑ .ﺪﯿﻨﯿﺒﺑ ﺍﺭ ﺮﯾﺯ ﻝﺎﺜﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺩﻮﺷ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﻥﺭﺪﻣ ﯼﺎﻫﺮﮔﺭﻭﺮﻣ ﻡﺎﻤﺗ ﺭﺩ :ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﻪﺘﺷﺭ ﯼﺎﻫﺮﺘﮐﺍﺭﺎﮐ ﺝﺍﺮﺨﺘﺳﺍ ﯼﺍﺮﺑ ﺵﻭﺭ 3 [ ] ﮏﻠﻣ ﻪﺑ ﯽﺳﺮﺘﺳﺩ .ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺺﺨﺸﻣ ﺭﺍﺪﻘﻣ ﮏﯾ ﺭﺩ ﺍﺭ ﺮﺘﮐﺍﺭﺎﮐ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﺮﺘﮐﺍﺭﺎﮐ ﺪﮑﯿﻧﻮﯾ .ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ (65535 ﻭ 0 ﻦﯿﺑ ﺢﯿﺤﺻ ﺩﺪﻋ ﮏﯾ) UTF-16 ﺪﮐ ﮏﯾ ﺵﻭﺭ ﻦﯾﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ECMAScript 5 (2009) ﺪﻫﺩ ﯽﻣ ﺎﻫ ﻪﺘﺷﺭ ﺭﺩ ﺍﺭ [ ] ﯽﮔﮋﯾﻭ ﻪﺑ ﯽﺳﺮﺘﺳﺩ ﻩﺯﺎﺟﺍ: → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺪﺷﺎﺑ ﯽﻨﯿﺑ ﺶﯿﭘ ﻞﺑﺎﻗﺮﯿﻏ ﯽﻤﮐ ﺖﺳﺍ ﻦﮑﻤﻣ ﯽﯾﺍﺭﺍﺩ ﻪﺑ ﯽﺳﺮﺘﺳﺩ (ﺖﺴﯿﻧ ﺭﻮﻄﻨﯾﺍ ﺎﻣﺍ) ﺪﻨﮐ ﯽﻣ ﻪﯾﺍﺭﺁ ﻪﯿﺒﺷ ﺍﺭ ﺎﻫ ﻪﺘﺷﺭ .ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﯽﻟﺎﺧ ﻪﺘﺷﺭ ﮏﯾ()charAt ﻪﮐ ﯽﻟﺎﺣ ﺭﺩ ،ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ [ ] ،ﺪﺸﻧ ﺍﺪﯿﭘ ﯼﺮﺘﮐﺍﺭﺎﮐ ﭻﯿﻫ ﺮﮔﺍ (!ﺪﻨﮐ ﯽﻤﻧ ﺭﺎﮐ ﺎﻣﺍ) ﺪﻫﺩ ﯽﻤﻧ ﯽﯾﺎﻄﺧ "str[0]="A .ﺩﻮﺷ ﯽﻣ ﻩﺪﻧﺍﻮﺧ ﻂﻘﻓ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﯿﻨﮐ ﻞﯾﺪﺒﺗ ﻪﯾﺍﺭﺁ ﻪﺑ ﺍﺭ ﻥﺁ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ،ﺪﯿﻨﮐ ﺭﺎﮐ ﻪﯾﺍﺭﺁ ﻥﺍﻮﻨﻋ ﻪﺑ ﯼﺍ ﻪﺘﺷﺭ ﺎﺑ ﺪﯿﻫﺍﻮﺧ ﯽﻣ ﺮﮔﺍ :ﺩﺮﮐ ﻞﯾﺪﺒﺗ ﻪﯾﺍﺭﺁ ﻪﺑ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﻪﺘﺷﺭ ﻞﮐ ﻞﻣﺎﺷ ﯽﺘﺸﮔﺮﺑ ﻪﯾﺍﺭﺁ ،ﺩﻮﺷ ﻑﺬﺣ ﻩﺪﻨﻨﮐﺍﺪﺟ ﺮﮔﺍ ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﮏﺗ ﺯﺍ ﯼﺍ ﻪﯾﺍﺭﺁ ﯽﺘﺸﮔﺮﺑ ﻪﯾﺍﺭﺁ ،ﺪﺷﺎﺑ "" ﻩﺪﻨﻨﮐﺍﺪﺟ ﺮﮔﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺪﯾﻭﺮﺑ ﺎﻣ ﺱﺭﺩﺁ ﻪﺑ ،ﻪﺘﺷﺭ ﻞﻣﺎﮐ ﻊﺟﺮﻣ ﮏﯾ ﯼﺍﺮﺑ .ﺪﯿﻨﮐ ﻞﻣﺎﮐ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ ﻊﺟﺮﻣ .ﺖﺳﺍ ﻪﺘﺷﺭ ﯼﺎﻫ ﺵﻭﺭ ﻭ ﺎﻫ ﯽﮔﮋﯾﻭ ﻡﺎﻤﺗ ﺯﺍ ﯽﯾﺎﻫ ﻪﻧﻮﻤﻧ ﻭ ﺕﺎﺤﯿﺿﻮﺗ ﯼﻭﺎﺣ ﻊﺟﺮﻣ
Chrome 66
Edge 79
Firefox 61
Safari 12
Opera 50
Apr 2018
Jan 2020
Jun 2018
Sep 2018
May 2018
trimEnd() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ
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>
trimEnd()
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ
Chrome 66
Edge 79
Firefox 61
Safari 12
Opera 50
Apr 2018
Jan 2020
Jun 2018
Sep 2018
May 2018
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ ﯼﺪﻨﺑ ﻪﯾﻻ
padStart()
padStart() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻪﺘﺷﺭ
padStart()
ﺵﻭﺭ ﺎﻫ ﻝﺎﺜﻣ
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>
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()
ﺩﻮﺷ ﯽﻤﻧ ﯽﻧﺎﺒﯿﺘﺸﭘ ﺭﺭﻮﻠﭙﺴﮐﺍ ﺖﻧﺮﺘﻨﯾﺍ ﺭﺩ. ﯼﺍ ﻪﺘﺷﺭ ﯼﺎﻫﺮﺘﮐﺍﺭﺎﮐ ﺝﺍﺮﺨﺘﺳﺍ
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()
ﺵﻭﺭ ﻝﺎﺜﻣ
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>
ﻝﺍﻮﻣﺍ ﻪﺑ ﯽﺳﺮﺘﺳﺩ
ﻝﺎﺜﻣ
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>
ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ
ﻝﺎﺜﻣ
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>
ﻪﺘﺷﺭ ﻞﻣﺎﮐ ﻊﺟﺮﻣ