WeChat mini-Program Development Series (3)-Javascript important character operation functions, program development javascript

Source: Internet
Author: User

Mini-Program Development Series (3)-Javascript important character operation functions, program development javascript

First of all, I wish you a happy new year's day. My "SMS timed reminder" mini-program was very successful. Many of my friends thought it was great to use this feature and they have already registered as members. Thank you for your support!

Your support is my motivation for continuous improvement.

The next step is to make it easier for users to use.

How to use it more conveniently is of course a variety of convenient operations on the mobile phone end. Today we will share with you the most important Javascript character operation functions in this tutorial. As for how to use them in the future, the results will be announced after I upload the code later.

1. Replace arrays with strings -- join

The array element needs to be connected to a string using a character. The sample code is as follows:

Var arrmobile, strmobile;
Arrmobile = new Array (13811112222, 13911112222, 15111112222 );
Strmobile = arrmobile. join ("-");

Console. log (strmobile );

Result:

13811112222-13911112222-15111112222


Note: This function is very useful because there are often many checkboxes in actual operations. If you want to perform character operations and splice the content of the checkbox, this function is essential.


2. Convert string to array -- split

To convert a string to an array, the sample code is as follows:

Var strmobile = "13811112222-13911112222 ";

Var arrmobile = strmobile. split ("-");

Console. log (arrmobile );


Result:

(2) ["13811112222", "13911112222"]


Note: This function is also very useful. The arrays and strings produced by each control are exchanged with each other. After processing, it will bring great convenience to the system.


3. Automatic Generation of character interval -- substr

The actual substr is used to find out the meaning of the sub-string. Here we use it to implement the automatic insertion interval. The sample code is as follows:

Var data = "138111122221"; // raw data var douhao = data. substr (11, 1); // you can specify 12th characters. if it is a comma, It is not processed. if not, insert the comma if (douhao! = ',') {Var tmp = data. substr (0, 11) + ',' + douhao; console. log (tmp );
}

Result:

13811112222,1


As you can see, this function is very powerful, and automation is very convenient for users, and it is widely used.


Let's talk about this today. You will be able to understand the advantages of these functions by yourself. May you think about it in 2018!


Finally, let's take a look at the "SMS timed reminder" applet I developed. You can also do better. Scan the code and try it,

You can also do better!




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.