How to Get String Length in Javascript?

07-Apr-2023

.

Admin

How to Get String Length in Javascript?

This tutorial is focused on how to get string length in javascript. we will help you to give example of javascript string.length. This post will give you simple example of javascript string length property. you can understand a concept of how to get the length of a string in javascript . follow bellow step for how to check string length in javascript.

To get the length of a string in JavaScript, you can use the `length` property. Here is an example:

Example 1:


<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>How to Get String Length in Javascript? - NiceSnippets.Com</title>

</head>

<body>

</body>

<script type="text/javascript">

const myString = "Hello, World!";

const stringLength = myString.length;

console.log(stringLength); // Output: 13

</script>

</html>

In this example, we declare a variable `myString` and assign it the value `"Hello, World!"`. We then use the `length` property to get the length of the string and assign it to a variable called `stringLength`. Finally, we log the value of `stringLength` to the console.

Note that the `length` property returns the number of characters in a string, including white spaces and punctuation marks.

#JavaScript