Home > Back-end >  JavaScript's built-in objects
JavaScript's built-in objects

Time:09-27

JavaScript's built-in objects
Array, also can saying is a built-in objects;
It and our common similar object function, is used to store some different is normal object using a string value as the property name, and an array of
Is to use Numbers to as index operation element; An array of storage performance is better than ordinary objects, we often use an array to store in the development of
Some data,
Date the Date object (built-in objects)
Use the Date in the JS object to represent a time
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);
Create a specified time object
Need in the constructor is passed a time string as an argument:
Var date2=new Date (" 2020-03-23 12:34:12 ");
The console. The log (date2);
Gets the current date of the week, will return a value of 0 ~ 6, 0 said Sunday:
Var day=d.g etDay ();
The console. The log (day);
Gets the current month of the date object
Returns a value of 0 ~ 11, 0 means in January, February 1, December 11 said:
Var month=d.g etMonth ();
The console. The log (month);
To obtain object with four number return year:
Var year=d.g etFullYear ();
The console. The log (year);
Gets the current date object hours var hours=d.g etHours ();
Gets the current date object minutes var minute=d.g etMinutes ();
Gets the current date object number of seconds the var second=d.g etSeconds ();
The Math object
Unlike 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, such as:
Math. Said PI PI (approximately equal to 3.14159
Math integer
Math.h ceil () : can be up to a number of integer, decimal places as long as there is value is automatically into 1
Math. The floor () : can be carried out on a number of integer down, the decimal part will be down
Math. The round () : can be carried out on a number rounded integer
Math random
Math. The random () : is a random number between 0 and 1, not including 0 and 1
  • Related