Directory
- Date Object
- Math Object
- Array Object
- String Object
- Regular Expression Object
What is an object
Objects have properties and methods, properties of various data types, and methods to manipulate the data in a property.
Object of JavaScript
- Built-in objects
Date, Array, String, Math, number, and so on
- Browser Object
Window, Frame, Navigator, History, location, screen, document, etc.
- Custom Objects
Date Object
- var Date object = new Date ()
- var Date object = new Date (number of milliseconds)
- var Date object = new Date (string)
- var Date object = new Date (year, month, day, etc. parameters)
var mydate=new Date(5000);var mydate=new Date( );document.write(mydate);
Time: UTC Global Standard Time, also known as Greenwich Mean Time, utc+800 refers to 8 hours earlier than Greenwich Standard Time, also Beijing time.
Method of the Date object
Parameters for the Date object method
- months:0 to 11
- Date:1 to 31
- Day:0 to 6
- hours:0 to 23
- Seconds and minutes:0 to 59
To method:
- toLocaleString
- toGMTString
var now= new Date( ) ;//获得当前日期和时间var hour = now.getHours() ;//获得小时,即当前是几点setTimeout( )方法每隔1秒调用显示时间
Math Object
The Math object, which is more complex than the inherited mathematical operations.
Common Properties and methods
PIabs(x)绝对值sin (x) 正弦random()随机数round(x)四舍五入sqrt(x)平方根
Array
var myarray= new Array ()
var myarray= []
Properties and Methods
lengthjoin()将数组中所有元素转化为字符串reverse()将数组中元素完全颠倒sort()排列数组
Traversal of an array
for (var i=0;i<MyArray.length;i++){ document.write(MyArray[i]);}for (var i in MyArray){ document.write(MyArray[i]);}
String Object
var str = new String (“这是字符串")
Common properties and methods for String objects
lengthsplit( )indexOf(“子字符串”,起始位置 ) lastIndexOf (“子字符串”,起始位置 ) charAt( index )
Regular expressions
Regular expressions are strings, divided into simple patterns and complex patterns.
var reg=/china/;var reg=/^\w+$/;
/[a-z0-9.] /can match any one character in A-Z, 0-9, and.
Regular expression symbols
\s 任何空白字符\d 匹配一个数字字符,等价于[0-9]\w 匹配一个数字、下划线或字母字符,等价于[A-Za-z0-9_]\W 任何非单字字符,等价于[^a-zA-z0-9_]
Conclusion
JavaScript Object Programming-3rd Chapter