Cascading Style Sheets (CSS) is used to design the layout of a webpage. CSS is a set of structured rules describing the layout of elements in
The length property of a String object returns the number of characters contained in a string.
const str = 'Get the length of this string'; console.log(str.length); // Expected output: 29
In the example above, str is a String containing 29 characters.
The length property counts all characters, including blank spaces and special characters.
Knowing the length of a String is useful in multiple different scenarios:
- Looping through a string with a for statement
- Displaying a shortened version of a string if the text is too long
- Verifying that a certain number of characters were entered for an input (e.g. username or password)
There are many more scenarios where String.length is useful – the only limit is your imagination.
The syntax of the String object’s length property is as follows:
This property returns the length of the associated string.
The length of an empty string is 0 (zero).
The Assignment operator is used to assign a value to a variable. Assignment (=) The assignment operator simply assigns the value of the right operand to
The for…in statement is used to loop through an object’s properties. Basic for…in loop example The following code demonstrates a basic example using the for…in statement