How to get the length of a string

Description

The string length is the number of 16-bit characters in the string.

The length of any string can be returned by using the length property as follows:



var text = "This is a test.";
console.log(text.length); 

Example

The length of a string can be returned by using the length property:


var firstName = 'first';
console.log(firstName.length);

The code above generates the following result.





















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions