JavaScript Object Programming-3rd Chapter

Source: Internet
Author: User

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
    1. var Date object = new Date ()
    2. var Date object = new Date (number of milliseconds)
    3. var Date object = new Date (string)
    4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.