Translate

Total Pageviews

JavaScript String Methods

 JavaScript String Methods

String methods help you to work with strings.

String Methods and Properties

Primitive values, like "John Doe", cannot have properties or methods (because they are not objects).

But with JavaScript, methods, and properties are also available to primitive values, because JavaScript treats primitive values as objects when executing methods and properties.

JavaScript String Length

The length property returns the length of a string:

====================

<!DOCTYPE html>

<html>

<body>

  <h2>JavaScript String Properties</h2>

  <p>The length property returns the length of a string:</p>

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

  <script>

  let text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  document.getElementById("demo").innerHTML = text.length;

  </script>

</body>

</html>

====================

Result:

JavaScript String Properties

The length property returns the length of a string:

26