string 的 API
The essence of all string arrays are the first point
All string of API has the right to modify the original string, can only return new string
str .toupperCase (); all uppercase letters are transferred
str.toLowerCase (); all lowercase letters are transformed into
var char = str.charAt (i); obtaining position specified character position i
str.charCodeAt (i); obtaining unicode code specified position i
string.fromCharCode (n); converted to a unicode character code
str.slice (i, n) from the selected word to n-1, i
str.indexOf; return keyword position, from zero by default, from front to back, only to return the first matching position
str.search (/ regular /); return to find the position of the first keyword, it returns -1 if not found, add i not case-sensitive
str.match (/ regular /); returns the character in the first found to meet the requirements of a return in the form of an array, if you want to return all meet the conditions on the plus g, with particular attention to the data to check whether the return is null
str.replace (/ regular / "replacement value"); the string matching content into replacement value, authority to modify the original content, with a new variable receives the return value.
str.split (/ regular /); cutting the string array, the return value does not include a delimiter.
Math object
And various other objects that can not use the new keyword Math object
This object is specialized encapsulates an amount commonly used mathematical calculations and provides an API used for mathematical calculations, the following summarizes several commonly used
First to introduce rounding API
Next integer 1.Math.ceil (num) rounded up to take num
2.Math.floor (num) rounded down, omitting the decimal part of the parameters are converted to digital, rounding
3.parseInt (str) will all be converted to a string, and then read the character bits
4.Math.round (num) rounded to the nearest whole Disadvantages: can only fetch! Advantages: returns the number can be directly subtraction
5.toFixed (d) by any decimal rounding disadvantages: The return value is a string, must be converted to digital, to calculate advantages: can be rounded in any decimal places
The random number returned is any number between. 1 ~ 0
the console.log (Math.random ());
Power: Math.pow (base, power)
Open square Math.sqrt (n);
Maximum and minimum parameters unsupported array
the console.log (Math.max (10,20,3,5,60));
the console.log (Math.min (10,20,3,5,60));
Date Object
API encapsulates a time of the operation
1 var now=new Date();
Self obtain client system time
2var date =new Date("2019/08/03");
Own to create a custom time
3. var date1 =new date("2019/08/03 13:54:00");
var date2=new date(date1);
This is the right value assigned to date2 date1 to create a new Date object
var date=new Date(ms);
With the number of milliseconds to create a date object
var date3=new Date(now);
was date4 = date3-date2;
console.log(date4);
The results output from the current time, this is the number of milliseconds between 2019/08/03 13:54:00 and the time difference
Date objects do two operations are managed by their number of milliseconds to do the operation.