Home  >  Article  >  Web Front-end  >  String string object

String string object

WBOY
WBOYOriginal
2016-09-03 00:00:111279browse

String objects have been used in previous studies. The way to define a string is to assign a value directly. For example:

<span style="color: #0000ff;">var</span> mystr = "I love JavaScript!"

After defining the mystr string, we can access its properties and methods.

Access the property length of the string object:

stringObject.length; Returns the length of the string.

<span style="color: #0000ff;">var</span> mystr="Hello World!"<span style="color: #000000;">;
</span><span style="color: #0000ff;">var</span> myl=mystr.length;

After the above code is executed, the value of myl will be: 12

Methods to access string objects:

Use the String object’s toUpperCase() method to convert string lowercase letters to uppercase:

<span style="color: #0000ff;">var</span> mystr="Hello world!"<span style="color: #000000;">;
</span><span style="color: #0000ff;">var</span> mynum=mystr.toUpperCase();
以上代码执行后,mynum 的值是:HELLO WORLD!<br><br><strong><span style="font-size: 15px;">使用String对象的toLowerCase()方法来将字符串大写字母转换为小写</span></strong>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:String split split()Next article:String split split()