Home > front end >  JavaScript object of built-in summary (array Array_ date Date_Math object)
JavaScript object of built-in summary (array Array_ date Date_Math object)

Time:09-21

JavaScript object summary
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Development tools and key technology: Adobe Dreamweaver JavaScript
Author: Peng Qiwang
Time to write: on April 26, 2020,
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
JavaScript object
Built-in objects: object by ES standard, can be stored in any ES the implementation of the multiple attributes of different data

The host object

Custom objects
Built-in objects:
one Array (Array)
- an array of objects (built-in objects)
- similar to it and our common object function, also is used to store some values
- different is common object using a string as the attribute name
And as index operation element array is to use Numbers to
- index:
Starting from 0 index of integer is
- an array of storage performance is better than ordinary objects, we often use in the development of an array to store some data
The Array object properties:


Array: ordinary objects:
Name: attribute values: index value: the value:
Gender male 5 0
The Age of 12 4 undefined
Name three false zhangsan


1.//to create an array object
Var arr=new Array ();
The console. The log (typeof arr);//object
2. To add elements in the array
Grammar: array [index]=value
Arr [0]=12;
Arr [1]=34;

The console. The log (arr [2]);//undefined

3. Read the elements in the arrayGrammar: array [index]
If the index of does not exist to read, not returned an error but undefined
4. To obtain the length of the array, use length this attribute for the
Grammar: array length.
For a continuous array, using the length can access to the length of the array (the number of elements)
For the continuous array, use access to the array's largest length (index + 1)
Try not to create an array of discontinuous
5. Modify the length
- if you modify the length is more than the original length, the part will be more free
- if you modify the length is less than the original length, the more part will be deleted
Arr. Length=10;
console.log(arr); The empty

[JavaScript array literal]
1. Use to create an array literal
Var arr1=[];
Grammar: []
2. When using the literal creating arrays, can be specified in the create the array elements in the
3. Use the constructor to create an array, can also add elements at the same time, will add elements as constructor arguments, separated by using between elements,
4. An array of values can be any data type, object contains
Var arr6=[" hello ", 123, false, undefined, null);
5. In an array can hold function
Var arr7=[function () {alert (123);}, function () {alert (" helloworld ");}].
The console. The log (arr7 [0]);
6. A two-dimensional array
Var arr8=[
5-tetrafluorobenzoic [1],
,4,6,7 [1]
];
[JavaScript array method]
1. The concat () : to connect two or more arrays, and returns a result,
Var arr=[" Ming ", "little red", "little orange"].
Var arr1=[" black ", "green", "little blue"].
Var arr2=arr. Concat (arr1);
2. The join () : all the elements in the array into a string, separated elements with a specified delimiter,
Grammar: arrayObject. Join (separator)
Var STR=arr. Join (" ~ ~ ");
console.log(arr);//[xiao Ming, little red, orange]
The console. The log (STR);//xiao Ming ~ ~ little red ~ ~ little orange
3. Push () : adds one or more elements to the end of the array, and returns the new length, can will add elements as a method of parameter passing, so these elements will be automatically added to the end of the array, the method will be an array of new length as the return value is returned
ArrayObject. Push (newelement1, newelement2,... , newelementX)
4. The pop () : delete and returns the last element of an array of
Var result=arr. Pop ();
Arr. Pop ();
The console. The log (" result="+ result);
console.log(arr);
5. The unshift () : beginning to add one or more elements to an array, and returns a new array length, after insert element forward edge, index of other elements will in turn adjustment
Var num=arr. Unshift (" white ", "black");
The console. The log (" num="+ num);
console.log(arr);
6. The shift () : you can delete the first element of the array, and will be deleted elements as the return value is returned
Arr. Shift ();
Arr. Shift ();
[JavaScript array traversal]
1. Create an array
Var arr=[" Ming ", "little red", "little orange", "little blue", "little green"].
2. The so-called iterate through group, is to remove all elements in the array to
for(var i=0; IThe console. The log (arr [I]);
}
3. Create a function that can be extracted from arrPerson middle aged 18 years old Person, and then wrapped in to a new array and returns the
[JavaScript array traversal foreach (expand)]
1. Normally we are using a for loop to iterate through group,
JS also provides us with a method, is used to iterate through group
The forEach ()
Above - this method only supports Internet explorer browser
IE8 and under the browser does not support this method, so if you need compatible with Internet explorer, then don't use the forEach
If considering the compatibility or use a for loop
Var arr=[" Ming ", "little red", "little orange", "little blue", "little green"].
2. The forEach () method needs a function as a parameter
- like this kind of function, created by us but not from what we call, we call the callback function
- there are several elements in the array function will be executed several times, each time, the browser will traverse to the elements in the form of arguments passed in, we can define parameters to read the content
- the browser will pass three parameters in the callback function:
The first parameter, is currently being traversal element
The second argument, is currently being traversal of the index of the element
The third parameter, are traversing the array
Arr. ForEach (function (the value, the index, obj) {
//the console log (value);
The console. The log (index);
[JavaScript_arguments]
Every time when the calling function, the browser will be passed in two implicit parameters:
1. The function of the context object this
2. Wrap argument object the arguments
- the arguments is an array of class objects, it can also be spread by array index to operation, also can obtain the length of the
- when calling a function, we passed by the argument will be saved in the arguments
- the arguments. Length can be used to obtain the length of the argument
- even if we don't define parameters, can also pass the arguments to use arguments, more troublesome
The arguments [0] said the first argument
The arguments [1] said the second argument
- it has a property called the callee,
This attribute corresponds to a function object, which is the current executing function object

two JavaScript Date object Date
The Date object (built-in objects)
- use the Date in the JS object to represent a time
Var d=new Date ();
The console. The log (d);//the current code execution time
1. Create a Date object
If the time use the constructor creates a Date object, will be encapsulated in the current code execution time
Var date2=new Date (" 2020-03-23 12:34:12 ");
The console. The log (date2);//the 2020-03-23 12:34:12/
2. The getDate () - gets the current date object when a couple of days, return the date and time of the day,
Var date=d.g etDate ();
3. GetDay () - gets the current date of the week, will return a value of 0 ~ 6
0 said on Sunday, 1 said Monday... , 6 said Saturday
Var day=d.g etDay ();
4. GetMonth () - gets the current month of the date object
- will return a value of 0 ~ 11, 0 means in January, February 1,... , December 11 said
Var month=d.g etMonth ();
5. GetFullYear () - access object with four number return date
Var year=d.g etFullYear ();
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 the number of seconds to
Var second=d.g etSeconds ();
6. GetTime ()
Object - to get the current date timestamp
- a timestamp, refers to from Greenwich mean time on January 1, 1970, 0 0 0 seconds
Cost to the current date (the number of milliseconds (1 second=1000 milliseconds)
- the underlying computer used in the preservation time is timestamp
7. You can use the timestamp to test the performance of the code
//get the current timestamp
Var start=Date. Now ();
for(var i=0; I<100; I++) {
The console. The log (I);
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related