Home > Back-end >  JavaScript object of built-in summary (array Date_Math Array_ date object, etc.)
JavaScript object of built-in summary (array Date_Math Array_ date object, etc.)

Time:09-28



~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Development tools and key technology: Adobe Dreamweaver JavaScript
The author: wang
Time to write: on April 25, 2020,
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Knowledge points list:
All things in JavaScript are objects: strings (String), Number (Number), Array (Array), Date (Date), and so on,
In JavaScript, object is to have properties and methods of data,
1 Date (Date) object: use the Date in the JS object to represent a time
I. create a Date object
If the time use the constructor creates a Date object, will be encapsulated in the current code execution time
Var d=new Date ();
The console. The log (d); - the browser return value - & gt; The current computer time
II. Create a specified time object
Need in the constructor is passed a time string as a parameter
Var date2=new Date (" 2020-03-23 12:34:12 ");
The console. The log (date2); - the browser return value - & gt; Mon Mar 23, 2020 12:34:12
III. GetDay () to get the current date of the week, will return a value of 0 ~ 6, 0 said on Sunday, 1 said Monday...
, 6 said Saturday,
IIII. GetMonth () for current month of the date object, returns a value of 0 ~ 11 (digital ditto) in the corresponding rules
\ Get \ FullYear \ Hours () () you () \ Seconds () \ obtain object with four number return, years, Hours, Minutes, Seconds,
V.g etTime () : get the current date object timestamp (timestamp, refers to from Greenwich mean time on January 1, 1970, 0 0 0 seconds to the current date when it takes the number of milliseconds (1 second=1000 milliseconds) the underlying computer used in the preservation time is timestamp
2. The Number (Number) object: Math object and other objects, it is not a constructor, it belongs to a utility class don't have to create the object, it encapsulates the mathematics related attributes and methods, is used to perform common arithmetic tasks, Math object provides a variety of numerical value type and function, without before using this object to define it,
Use Math methods of attribute/syntax:
Var a=Math. Abs (x) - returns the absolute value of a number
Var b=Math. Sin (x) - returns the sine of a number
Var c=math.h ceil () - can be up to a number of integer, decimal places as long as there is value is automatically into 1
Var d=Math. Floor () - can be carried out on a number of downward integer, decimal portion will be down
Var e=Math. The round () - a number can be rounded integer
Var f=Math. The random () - can be used to generate a random number between 0 and 1
By this formula and other formula above match can derive a lot of, such as:
Generate a random number between 0 and 10 (integer) : math.h round (Math) random (10), etc.,
3. The strings (String) :
3.1 relevant methods of string
Var STR="wangmin";
In the underlying string in the form of an array to save
"W" [0, 1 "a", 2 "n", 3 "g", 4 "m"...
The console. The log (STR [6]); - the browser return value - & gt; N
The length of the string. The console log (STR) length); - the browser return value - & gt; 7
CharAt () : returns the specified location in a string of characters. According to the index for the specified character
The console. The log (STR. CharAt (4)); - the browser return value - & gt; M (here why don't I just use an array? So easy to remember and easy, don't understand?????? )
3.2 indexOf () "wangmin";
Whether the method can retrieve a string containing the specified content
If the string is contained in the content, the first time will return to the index of the
If it didn't find the contents of the specified return 1
You can specify the second parameter, began to find the location of the specified
3.3 lastIndexof ()
The method of usage and indexOf ()
Different is indexOf is once upon a time in the future,
The lastIndexof from backward looking for
You can also specify began to find the location of the
Var result=STR. IndexOf (" w ");//0
Result=STR. IndexOf (" v ");//- 1
Result=STR. IndexOf (" w ", 3);//4
3.4 slice ()//STR="hello world";
- can intercept from the string specified content
- will not affect the original string, but intercepted back content
- parameters description:
Beginning of the first argument: index (including starting position)
End of the second parameter: the location of the index (not including end position)
- if you omit the second argument, may be intercepted back all the
- can also pass a negative number as a parameter, negative words will count from behind
Result=STR. Slice (2, 5);//baotou tail package, the return value, & gt; Ngmi
Result=STR. Slice (2);//baotou tail package, the return value, & gt; Ngmin
3.5 the substring ()
- can be used to capture only a string, and the slice () is similar to
- parameters description:
Beginning of the first argument: index (including starting position)
End of the second parameter: the location of the index (not including end position)
- if you omit the second argument, may be intercepted back all the
- the difference is this method cannot receive negative, if passing a negative value, the default is 0
- if the second argument is less than the first parameter, automatically switch position
Result=STR. The substring (2, 6);//baotou tail package, the return value, & gt; Ngmin
3.6 toUpperCase () : converts a string to uppercase and return toLowerCase () converts a string to lowercase and return
Split () a string can be called an array of split parameters: need a string as a parameter, will according to the string to break up the array
Var STR="ihs. Question. The history".
Var arr=STR. The split (". "); {" "what's in here on the basis of what separates the inside of the STR string formed an array, if the STR split (" I"), the inside of the STR string is an array of [" h ", "Sheldon horowitz", "m.h", "story"]}
console.log(str); - the browser return value - & gt; Ihs. Question. The history
console.log(arr); - the browser return value - & gt; [" his ", "question", "history"]
Zero: "his"
1: "question"
2: "the history"
Length: 3 (here the ihs. Question. "history" separated with ". "these words into three portions of an array)