String string object

WBOY
Release: 2016-09-03 00:00:11
Original
1254 people have browsed it

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!"
Copy after login

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;
Copy after login

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();
Copy after login
以上代码执行后,mynum 的值是:HELLO WORLD!<br><br><strong><span style="font-size: 15px;">使用String对象的toLowerCase()方法来将字符串大写字母转换为小写</span></strong>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!