Basic String Methods
JavaScript strings are primitive and immutable, meaning that all string methods produce a new string without altering the original.
JavaScript String Length
The length property retrieves the length of a string.
Example
<!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>
Extracting String Characters
Four methods are available for extracting string characters:
- The at(position) Method
- The charAt(position) Method
- The charCodeAt(position) Method
- Using property access [] similar to arrays.
JavaScript String charAt()
The charAt() method retrieves the character at a specified index (position) in a string.
Example