Javascript Function String
Javascript Function String
<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The length Property</h2>
<script>
let text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
document.getElementById("demo").innerHTML = text.length;
</script>
</body>
</html>
2.<html>
<body>
<h1>JavaScript String</h1>
<h2>The charAt() Method</h2>
<p id="demo"></p>
<script>
var text = "HELLO WORLD";
document.getElementById("demo").innerHTML = text.charAt(0);
</script>
</body>
</html>
3.<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The at() Method</h2>
<p id="demo"></p>
<script>
const name = "W3Schools";
let letter = name.at(2);
document.getElementById("demo").innerHTML = letter;
</script>
</body>
</html>
4.<html>
<body>
<h1>JavaScript Strings</h1>
<h2>Bracket Notation</h2>
<p id="demo"></p>
<script>
const name = "W3Schools";
let letter = name[2];
document.getElementById("demo").innerHTML = letter;
</script>
</body>
</html>
5.<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The indexOf() Method</h2>
<p>The indexOf() method returns the position of the first occurrence of a string in a string.</p>
<p>The position of the first occurrence of "locate" is:</p>
<p id="demo"></p>
<script>
let text = "Please locate where 'locate' occurs!";
let index = text.indexOf("locate");
document.getElementById("demo").innerHTML = index;
</script>
</body>
</html>
6.<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The lastIndexOf() Method</h2>
<p id="demo"></p>
<script>
let text = "Please locate where 'locate' occurs!";
let index = text.lastIndexOf("locate");
document.getElementById("demo").innerHTML = index;
</script>
</body>
</html>
7.<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The indexOf() Method</h2>
<script>
let text = "Please locate where 'locate' occurs!";
let index = text.indexOf("John");
document.getElementById("demo").innerHTML = index;
</script>
</body>
</html>
8.<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The search() Method</h2>
<p>The search() method returns the position of the first occurrence of a string in a string.</p>
<p>The position of the first occurrence of "locate" is:</p>
<p id="demo"></p>
<script>
let text = "Please locate where 'locate' occurs!";
let index = text.search("locate");
document.getElementById("demo").innerHTML = index;
</script>
</body>
</html>
9.<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The search() Method</h2>
<p>The search() method returns the position of the first occurrence of a string in a string.</p>
<p>Return the position of the first occurrence of a regular expression:</p>
<p id="demo"></p>
<script>
let text = "Please locate where 'locate' occurs!";
let index = text.search(/locate/);
document.getElementById("demo").innerHTML = index;
</script>
</body>
</html>
10.<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The match() Method</h2>
<p id="demo"></p>
<script>
let text = "The rain in SPAIN stays mainly in the plain";
const myArr = text.match("ain");
document.getElementById("demo").innerHTML = myArr.length + " " + myArr;
</script>
</body>
</html>