JS built-in object-string, Date Date object, array array object, Math object

Source: Internet
Author: User

all things in JavaScript are objects: strings, arrays, numbers, functions ...1, each object with properties and methods

JavaScript allows custom objects

2. Custom Objects

A. Define and create an object instance

B. Use a function to define the object, and then create a new object instance

Second, JS built-in object-string1. String Object

String object to handle an existing string

strings can use single or double quotation marks

2, IndexOf () find the string in the string, if the match successfully returns the position of the first letter, otherwise return-1

3. Match ()Match succeeds, returns an array of successful matches, otherwise returns null

4. ReplaceStr.replace (Find the character, new string) matches successfully, with new character to replace match successful character

5. Convert toUpperCase () to uppercase

Common properties and methods include the following:

Properties: Length, prototype, constructor

Methods: CharAt (), charCodeAt (), concat (), IndexOf (), Match (), replace (), search (), slice (), substring (), substr (), ValueOf (), toLowerCase (), toUpperCase (), Split ()

Third, JS built-in object-date date1. Date Object

Date objects are used to process dates and times

2. Date of the day of acquisition

3, the common method:

Year of Acquisition: getFullYear ()

Get month: GetMonth (+1)

Date taken: GetDate ()

Get week: GetDay ()

Get Hours: Gethour ()

Get minutes: getminutes ()

Get seconds: getseconds ()

Get milliseconds: GetTime ()

Four, JS built-in object-array1. Array Object

Use a separate variable name to store a series of values

2. Creation of arrays

Eg:var Myarr = ["Hello", "World", "HI"]

3. Access to arrays

You can access a specific element by specifying the array name and the index number

Note: [0] is the first element of the array. [1] is the second element of the array

4. Common methods of arrays:

Concat () Merging arrays

Sort () sorting

Append element at end of push (), return length

Reverse () array element rollover

Five, JS built-in object-math1. Math Object

Perform common arithmetic tasks

2, the common method:

Rounding: Round ()

Returns the random number between 0~1: Random ()

Return highest value: Max ()

Return lowest value: Min ()

Return absolute Value: ABS ()

JS built-in object-string, Date Date object, array array object, Math object

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.