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 ); //