Javascript Object Property method summary_javascript tips-js tutorial

Source: Internet
Author: User
Tags base 10 logarithm natural logarithm
This article provides a detailed summary of Javascript Object attribute methods. For more information, see. Array: an ordered set of series Elements

Attribute:

Length: used to obtain the number of array elements, that is, the maximum subscript plus 1

Method:

Sort (function): If no sorting number is specified, it is arranged alphabetically by the elements. If it is not a string type, it is converted to a string;

Reverse (): reverses the order of elements in the array;

Concat (array1, arrayn): Used to combine N numbers and add them to the array1 array;

Join (string): Used to merge the elements in the array into a string, and the string is the separator. If any parameter is omitted, the elements are directly merged without additional points;

Slice (start, stop): Used to return the elements from start to stop in the array. If the parameter is negative, it indicates the reciprocal start or stop element;

ToString (): returns a string of all elements in the array separated by commas;

String)

Attribute:

Length: returns the length of a string. It is used in the same way as an array;

Method:

Anchor (): This method creates a tag in the same format as the anchor in HTML. Use the following method to access string. anchor (chorName)

ToUpperCase (): converts a string to uppercase;

ToLowerCase (): converts a string to lowercase;

IndexOf (a, B): searches for the position where character a appears in the string from character B and returns the result. If B is omitted, it searches from position 0 by default;

ChartAt (I): returns the I-th character in the string;

Substring (start, end): returns all characters in the string between start and end (but does not return the character of end itself );

Sub (): displays the specified string in subscript format;

Date: For details, see

Definition method:

A: var newdt = new Date () --> Create a time object and assign a value to the current time;
B: var newdt = new Date (milliseconds) --> Create time object, and set the object Value in milliseconds Based on the delay time of GTM;
C: var newdt = new Date (string) --> assign values to the newly created time object using a specific time string. The format matches the parse method of the Date object;
D: var newdt = new Date (year, month, day, hour, minute, second, millisecond) --> by year, month, day, hour, minute, second, assign values to objects in milliseconds;

Method: get time, set time, format conversion

A: Get time

GetDate () ----- get the current complete time;
GetYear () ------ get the current year
GetMonths () ---- get the current month
GetDay () ------- get the current date day
GetHours () ----- get the current hour
GetMinutes () --- get the current minute
GetSeconds () --- get the current second
GetTime () ------ get the current time, in seconds
GetTimeZoneOffset -- get the current time zone offset Information

B: set the time.

Replace get with set, for example, getDate () ---> setDate ()

C: Conversion Method

ToGTMString () ------ convert to the string of the Greenwich Mean Time expression;
ToLocaleString () ---- convert to a string expressed locally
ToString () ---------- convert time to string
Parse --------------- read the time from the string that represents the time
UTC ----------------- returns the gap from Greenwich Mean Time to the specified time, in milliseconds


Math mathematics:

Attribute: note that attributes in a mathematical object refer to read attributes.

E (= 2.7182) ------ bottom of the natural logarithm (I don't understand what it means, alas, I don't understand anything close to mathematics, I'm depressed !)
LN10 (= 2.30259) --- the natural logarithm of 10;
LN2 (= 0.69315) ----- natural logarithm of 2;
PI (= 3.1415926) ---- circumference Rate
SQRT1_2 (= 0.7071) -- square root of 1/2
SQRT2 (= 1.4142) ---- the square root of 2
LOG2E (= 1.44269) --- base on 2, logarithm of E
LOG10E (= 0.43429) -- base 10 logarithm of E

Method: Actually, I don't have much to use. I'm depressed. Let's get it all out.

Sin (a) ---- returns the sine of.
Cos (a) ------ calculate the cosine of
Tan (a) ------ returns the tangent of
Asin (a) ----- returns the arc sine of.
Atan (a) ----- returns the arc cosine of.
Exp (a) ------ calculate the index of
Log (a) ------ calculate the natural logarithm of
Pow (a, I) ---- calculate the I power of a (multiplication)
Round (a) ---- rounding
Sqrt (a) ----- calculate the square root of
Abs (a) ------ calculate the absolute value of
Random () ---- random Number
Max (a, B) ---- take a large number
Min (a, B) ---- take a smaller number

Note: All function parameters are of the floating point type. The trigonometric function parameters are radians, rather than degrees.

JavaScript built-in functions

Escape () and unescape (): encoding and decoding strings

Eval (string): used to execute operations or statements represented by strings
For example: var a = 0; var str1 = "a + = a"; eval (str1 );

ParseInt () and parseFloat (): Convert the value of the text box to an integer or floating point number.

Note: parseInt () is not used to round the number, but to cut the end.

IsNaN (): The complete E is (is not a number). As the name suggests, it is used to determine whether the string is a number, for example, if (isNaN ("tianbang series tutorial "))

Custom object: There are two methods to initialize objects and define constructor objects.

A: initialization object

For example, object = {property 1: value 1; Property 2: Value 2;... property n: value n}. Note that each property value pair is separated by a semicolon;

B: define the object of the constructor.

For example:
Function Name (attribute 1, attribute 2 ,... Attribute N ){

This. Attribute 1 = attribute value 1;
This. Attribute 2 = attribute value 2;
This. Attribute n = attribute value n;

This. method name 1 = function name 1;
This. method name 2 = function name 2;
}

Note: The method name and function name can have the same name. However, before calling a function, the function must be defined. Otherwise, an error occurs.

The new statement is used to create a new instance for a custom function.

Browser object

Window object:He belongs to the central level and is at the highest level of all objects. To put it bluntly, you can play without him;

Attribute:

Closed ---------- used to determine whether the window is closed;
Er ---------- store () method to open the parent window of the window;
Defaultstatus --- information displayed by default in the status bar;
Status ---------- information currently displayed in the status bar;
Document, Location, History --- very important. If you don't want to wait for it, read it here.

Method:

Alert (text) ------------- a prompt box is displayed.
Confirm (text) ----------- confirmation information box, the parameter is confirmation Information
Prompt (text, default) ---- the input dialog box is displayed. The parameters are the prompt information and default values.


Document Object:Includes various features of the current webpage, such as the title URL, background, language, and modification time.

Attribute:

Title ------------ document title
LastModified ----- last modification time of the object
URL -------------- URL of the document
Cookie ----------- create and obtain Cookie Information
BgColor ---------- background color of the document
FgColor ---------- foreground color of the document
Location --------- save all the page address information of the document
Alinkcolor ------- activation connection color
Linkcolor -------- link color
Vlinkcolor ------- color of the browsed Link

Method:

Write (text) ----- write text or labels to the document without line breaks
Writeln (text) --- write text or tags to the document and wrap the line at the last character
() ---------- Open a new document, for example ("Address", "window name", "style ")
Close () --------- close the current document

Location object:Contains all the page addresses of the current document

Attribute:

Protocol ----------- communication protocol
Host --------------- host Name of the WEB server where the page is located
Port --------------- port number for server communication
Pathname ----------- path of the document on the server
Hash --------------- information about the page Jump anchor tag
Searce ------------- information submitted to the server for search
Hostname ----------- host name and port number, separated by a colon
Href --------------- complete URL

Method:

Assign (URL) -------- navigate the page to another address
Reload ------------- refresh the page
Replace (URL) ------- replace the current page with the specified URL

History:This object includes previously accessed URL Information

Attribute: length, number of returned URLs

The main method is go (n). This method is used to load the relative page.

Related Article

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.