String string object, String string object
The string object has been used in the previous study. The method for defining a string is to assign a value directly. For example:
Var mystr = "I love JavaScript! "
After defining the mystr string, we can access its attributes and methods.
Length:
StringObject. length; returns the length of the string.
Var mystr = "Hello World! "; Var myl = mystr. length;
After the above code is executed, the value of myl will be: 12
Method for accessing string objects:
Use the toUpperCase () method of the String object to convert lowercase letters of the String to uppercase:
Var mystr = "Hello world! "; Var mynum = mystr. toUpperCase ();
After the preceding code is executed, the value of mynum is hello world!
Use the toLowerCase () method of the String object to convert uppercase letters into lowercase letters.