Basic javascript packaging type, javascript Packaging

Source: Internet
Author: User

Basic javascript packaging type, javascript Packaging

① Number type

 

The Number type has some static attributes (properties called directly through the Number without the new operator) and methods.

 

 

// Var box = 1000.789; // alert (box. toString (); // convert to a string. Passing parameters can be converted to hexadecimal // alert (box. toLocaleString (); // local format, 1,000.789 // alert (box. toFixed (2); // 1000.79, retain two decimal places, rounding/alert (box. toExponential (); // exponential form, 1.000789e + 3 // alert (box. toPrecision (8); // 1.00e + 3, in exponential or vertex form. Select the value based on the parameter.

② String type

// Var box = 'aaabaabbq'; // alert (box. charAt (1); // A // alert (box. charCodeAt (2); // A, 97, the returned acsⅱ code // alert (box [0]); // alert (box. concat ('is', 'ddd '); // parameter string connection // alert (box. slice (4, 6); // aa // alert (box. substring (4, 6); // aa // alert (box. substring (-4); // negative number returns all // alert (box. substr (4, 6); // aaBbq // alert (box. substr (4,-4); // The second parameter is negative and is directly transferred to 0 // alert (box. substr (-4); // aBbq, 9 + (-4) = 5 digits start

// Var box = 'asbdfghjkla '; // alert (box. indexOf ('B'); // 2, returns the index value of B // alert (box. indexOf ('D', 2); // 3 // alert (box. lastIndexOf ('A'); // 10 // alert (box. lastIndexOf ('A', 9); // 0, search forward from the specified position
 

/* No-1 is found. For example, find all a * // var box = 'asbdfghjkla '; // var boxarr = []; // store the array at location a // var pos = box. indexOf ('A'); // obtain the location of the first a // while (pos>-1) {// greater than-1, indicating that a // boxarr exists. push (pos); // Add to array // pos = box. indexOf ('A', pos + 1); // re-assign the current position of the pos //} // alert (boxarr ); //


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.