2016.9.13 JavaScript Introductory six basic functions

Source: Internet
Author: User

1.math.random () function;

2.math.floor (x) returns the largest integer less than the parameter x, which is the rounding down of the floating-point number.

For example: The random itself only produces a decimal between (0~1), random () *10 meaning to produce a decimal between 0~10

3.Regular Expressions Regular expression: a regular expression is used to find certain words or patterns in a string.

For example: if we want to find in the string: Dog Chasing the cat, this string, we can use the following regular expression:/The/gi

How to use regular expressions:

/is the beginning of the regular expression.
The pattern we want to match.
/The end of the regular expression.

G means the global, which causes the pattern to return all matches in the string, not just one.

I mean when we are searching, ignoring the case mode;

Teststring.match (expression). The function of length is to return the number of and in the computed string;

4. Regular expression: Retrieves a numeric selector for a number in a string (for example, a number 9 through 0). In JavaScript, it's like this:/\d/g;

Add a plus sign (+) after the selection, for example:/\d+/g, allow this regular expression to match one or more numbers;

There are two numbers in this string, so the result is: 2;

5. We can also use regular expressions to select spaces in the preferred lookup string. Space characters: "", \ r (carriage return), \ n (newline), \ T (label), and \f (page break).

A regular expression of spaces looks like this:/\s+/g

In this string, there are 7 spaces, so the result of the regular expression retrieval is: 7;

6. Regular expression:/\s/g, which is used to retrieve all non-whitespace characters:

In this string, non-whitespace accounts for 49 strings, so the result of the retrieval is: 49;

2016.9.13 JavaScript Introductory six basic functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.