Common built-in objects

Source: Internet
Author: User
Tags mathematical constants

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. Working with objects
Objects are encapsulated by properties and methods
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 objects
Creating a String Object
property of the String object: Length
Case Conversion Method:
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
Querying the specified string
X.indexof (Findstr,[index])
X.lastindexof (Findstr,[index]) LastIndexOf: Looking up from behind
Get substring
X.substring (Start,[end])
Replace substring
X.replace (FINDSTR,TOSTR)
Splitting a molecule string
X.split (Bystr,[howmany]) returns the segmented array of strings Howmany: Specifies the maximum length of the returned array, which can be omitted
5.String objects and regular expressions
Method:
X.replace (REGEXP,TOSTR)
X.match (RegExp)
X.search (RegExp)
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
6.Array objects
Creating an Array Object
var cnweek = new Array (7);
var books = new Array ();
Initializing an Array object
var test = new Array (+, "a", true);
var books = [100,200,300];
var cnweek = new Array (7);
Cnweek[0] = "Sunday";
Gets the number of array elements:
Length Property
Creating a two-dimensional array
You can create two-dimensional or even multidimensional arrays by specifying how the elements in the array are arrays
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 the
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])
Use 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
7.Math objects
The Math object is used to perform math tasks
No constructor Math ()
No need to create, just use math as an object to invoke all of its properties and methods
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.
8.Number objects
The number object is the wrapped object of the original value
Create Number Object
var mynumber=12.567
Or
var myNum = new Number (value)
Or
var myNum = number (value)
ToString ():
numeric Conversions to Strings
ToFixed (num):
Values are converted to strings, and a certain number of digits after the decimal point are preserved
If necessary, the number is rounded, or it can be filled with 0
9.RegExp Object Overview
The RegExp object represents a regular expression, which is a powerful tool for performing pattern matching on strings
Creating a regular Expression object
var rgexp =/pattern/flags;
var rgexp = new RegExp ("pattern", ["flags"]);
The flags are identified in the following several:
G: Set current match to global match mode
I: Ignore case detection in match
M: Multi-line search mode
Common methods for 10.REGEXP objects
Regexpobject.test (String)
Returns True if the string contains text that matches regexpobject, otherwise false;
Reg.compile (Pattern,[flags]) compiling regular expressions
Reg.exec (STR) Retrieves the value specified in the string to return the found values and determines its location
Reg.test (STR) Retrieves the value specified in the string, returning True or false

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.