How to get the length of a string in JavaScript?
The property string.length
returns the number of bytes in a string, i.e. the length.
Example :
str ="Hello world";
len = str.length; // len = 11, the length of str
Warning : string.length
returns the number of bytes, not the number of characters. Some characters (UTF-8, UNICODE ...) are encoded on several bytes :
str ="????";
console.log (str.length); // Display 2
The property string.length
returns the number of bytes in a string, i.e. the length.
Example :
str ="Hello world";
len = str.length; // len = 11, the length of str
Warning : string.length
returns the number of bytes, not the number of characters. Some characters (UTF-8, UNICODE ...) are encoded on several bytes :
str ="????";
console.log (str.length); // Display 2
The property string.length
returns the number of bytes in a string, i.e. the length.
Example :
str ="Hello world";
len = str.length; // len = 11, the length of str
Warning : string.length
returns the number of bytes, not the number of characters. Some characters (UTF-8, UNICODE ...) are encoded on several bytes :
str ="????";
console.log (str.length); // Display 2
The property string.length
returns the number of bytes in a string.
Example :
str ="Hello world";
len = str.length; // len = 11, the length of str
Warning : string.length
returns the number of bytes, not the number of characters. Some characters (UTF-8, UNICODE ...) are encoded on several bytes :
str ="????";
console.log (str.length); // Display 2
# | ID | Query | URL | Count |
---|