Home > Web Front-end > JS Tutorial > Proficient in Javascript series data types string_javascript skills

Proficient in Javascript series data types string_javascript skills

WBOY
Release: 2016-05-16 18:06:05
Original
1061 people have browsed it

There are 9 data types in js, namely: undefined, null, boolean, string, number, object, reference, and list (completion). The latter three are only used as data types for the intermediate results of JS execution, so they cannot be used in code. Let’s talk about String first:
A string consists of zero or more characters. Characters can include letters, numbers, punctuation marks, and spaces. The word

string must be enclosed in single or double quotes:
------------------------------ ----
Example: var a='Magic pen small c';
var a="Magic pen small c";
--------------- ------------------
Single quotes and double quotes can be used casually. However, if the string contains double quotes, the entire string should be

Put it in single quotes;
The string has the length attribute, which can return the number of characters in the string
------------------------ ---------
Example:
var a="hell world";
alert(a.length);
Result: 11;
---- -----------------------------
Slice, substring, and substr methods are to take a substring from a string, where

slice and substring both accept two parameters, which are the starting position and the ending position of the substring, and return the substring between the two

, excluding the ending position. character. If the second parameter is not set, it will be from the starting

position to the end of the string.
Example:
Use Slice and substring methods to extract strings:

Copy code The code is as follows:



The results are as follows:
A,B
AB
-------- --------------------------
indexOf() and lastIndexOf() are very effective for search operations
Example:
Copy code The code is as follows:


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