JavaScript String Methods
JavaScript Basics

JavaScript String Methods

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:

  1. The at(position) Method
  2. The charAt(position) Method
  3. The charCodeAt(position) Method
  4. Using property access [] similar to arrays.

JavaScript String charAt()

The charAt() method retrieves the character at a specified index (position) in a string.

Example

Take a look into your desired course