Home >Web Front-end >JS Tutorial >JavaScript Learning Notes JS Object_Basic Knowledge
Default Object
Date object Date,
Format: date object name=new Date([date parameter])
Date parameter:
1. Omit (most commonly used);
2. English-numeric format: month, day, year [hour: minute: second]
For example: today=new Date("October 1,2008 12:00:00")
3. Numeric format: year, month, day, [hour, minute, second]
For example: today=new Date(2008,10,1)
Date object methods:
Format: date object name.Method ([parameter])
Usage example:
Current time: April 21, 2014, Monday 1, time: 14:7:53
Array object
The purpose of an array object is to store a series of values using separate variable names.
JavaScript arrays have two special features:
1. The array length is variable and can be automatically expanded;
2. The data types stored in the array do not need to be uniform, that is, different data types can be mixed.
Multiple formats for creating array objects:
new Array();
The returned array is empty and the length field is 0.
new Array(size);
The parameter size is the expected number of array elements. In the returned array, the length field will be set to the value of size. This constructor returns an array with the specified number of undefined elements.
new Array(element0, element1, ..., elementn);
This constructor will initialize the array with the value specified by the parameter, and the length field of the array will be set to the number of parameters.
Array object name=[Element 1[, Element 2,...]]
(Note that square brackets are used here).
When the constructor is called as a function without using the new operator, it behaves exactly the same as when it is called with the new operator.
You can also create two-dimensional arrays.
For the methods of Array object, please see: http://www.w3school.com.cn/jsref/jsref_obj_array.asp
Example of using array object:
字符串对象
建立字符串对象:
格式:字符串对象名称=new String(字符串常量)
格式:字符串变量名称="字符串常量"
一个验证Email的例子:
自定义对象
前面讲函数的时候讲过一个例子,现在这里再讲一下这个例子: