Common built-in objects

Source: Internet
Author: User

1. What is a JavaScript object

Object is the most important element in JavaScript

JavaScript contains multiple objects

Built-in objects

Custom Objects

Browser Object

HTML DOM Object

...

2. Using objects

objects are encapsulated by attributes and methods encapsulation

References to Properties

Use Point (.) Operator

Reference to the method of the object

Objectname.method ()

3. Common built-in objects

Simple Data Objects

String, number, Boolean

Group objects

Array, Math, Date

Advanced objects

Function, REGEXP

4. String Object

Creating a String Object

property of the String object: Length

5. Common methods of String objects

Uppercase and lowercase conversion methods

X.tolowercase ()

X.touppercase ()

Gets the specified character

X.charat (Index): Returns the character at the specified position

X.charcodeat (Index): Returns the Unicode encoding of the specified position character

Using annotations

Index: Character position

Querying the specified string

X.indexof (Findstr,[index])

X.lastindexof (Findstr,[index])

Using annotations

FINDSTR: String to find

Index: the indexed position at which to start the search can be omitted

Returns the first character position index that findstr appears in X, or 1 if not found

LastIndexOf: Looking up from behind

Get substring

X.substring (Start,[end])

Using annotations

Start: Starting position

End: Ending position plus 1, can be omitted

Replace substring

X.replace (FINDSTR,TOSTR)

Using annotations

FINDSTR: the string to find

TOSTR: The string to replace with

Returns the replaced string

Splitting a molecule string

X.split (Bystr,[howmany])

Using annotations

Bystr: Delimited string

Howmang: Specifies the maximum length of the returned array, which can be omitted

Returns an array of delimited strings

6. String object and regular expression

Method

X.replace (REGEXP,TOSTR)

X.match (RegExp)

X.search (Regex)

Using annotations

RegExp represents a regular expression or string

Replace returns the replaced result

Match returns an array of matching strings

Search returns the first character position index of the matched string

7. Array Object

Creating an Array Object

var cnweek=new Array (7);

var books=new Array ();

Initializing an Array object

var test=new Array (+, "a", true);

var test1=[100,200,30]

var cnweek=new Array (7);

Cnweek[0]= "Sunday";

Get the number of array elements: Length Property

8. Common methods of Array objects

Array conversion to string

X.join ([Bystr])

X.tostring ()

Using annotations

Returns the concatenated string

Bystr: As a string that joins an element in an array, you can omit

X.tostring (): Connected by a comma (,)

Connection array

X.concat (Value,...)

Using annotations

Value is concatenated to the end of the array as an array element

Returns an array after the connection

The Concat method does not change the value of x itself

Get sub-array

X.slice (Start,[end])

Using annotations

Start: Starting position index

End: Ending position plus 1, omitted is equivalent to intercepting all array elements from the start position

Array inversion and sequencing

X.reverse ()

Inverse array

Change the order of values in array x

X.sort ([Sortfunc]): Array sorting

Sortfunction: Optional, name of the function used to determine the order of the elements

9. Math Object

The Math object is used to perform math tasks

No constructor Math ()

unordered creation, which directly uses math as an object to invoke all its properties and methods

such as: Math.PI, Math.Round (3.56)

10. Common Properties and methods of the Math object

Common properties: All Mathematical constants

MATH.E (natural number)

Math.PI (PI)

MATH.LN2 (LN2)

Math.ln10 (LN10), etc.

Trigonometric function

Math.sin (x), Math.Cos (x), Math.tan (x), etc.

Inverse trigonometric function

Math.asin (x), Math.acos (x), etc.

Calculation function

MATH.SQRT (x), Math.log (x), Math.exp (x), etc.

Numeric comparison functions

Math.Abs (×), Math.max (x, y,...), Math.random (), Math.Round (x), etc.

11. Number Object

The number object is the wrapped object of the original value

Create Number Object

var mynum=12.567;

Or

var mynum=new number (value);

Or

var mynum=number (value);

12. Common methods for Number objects

ToString (): numeric value converted to string

ToFixed (num): Numeric value converted to a string and reserved for a certain number of digits after the decimal point

If necessary, the number is rounded, or it can be filled with 0

Common built-in objects

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.