Javascript object property method summary

  • 2020-03-29 23:52:22
  • OfStack

Array: an ordered collection of a series of elements


Length: gets the number of elements in an array, the maximum index plus 1


Sort (function): in the case of no sort number specified, arrange the elements in alphabetical order.

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

Concat (array1,arrayn): used to combine N Numbers into an array1 array;

Join (string): it is used to merge the elements in the array into strings. String is the separator.

Slice (start,stop): returns the elements from start to stop in the array. If the parameter is negative, it means the reciprocal start or stop elements.

ToString (): returns a string from all the elements of the array, separated by a comma;

String (string)


Length: returns the length of a string, as in an array;


Anchor (): this method creates the same markup as the anchor in HTML, format < A name = ""... > , to access string.anchor(chorName) by

ToUpperCase (): converts a string toUpperCase;

ToLowerCase (): converts a string toLowerCase;

IndexOf (a,b): find the position of character a in the string from the b character and return. If b is omitted, find from the 0 position by default.

ChartAt (I): returns the ith character in the string;

Substring (start,end): returns all characters in the string from start to end (but not the end itself);

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

Date: see details

Definition method:

A: var newdt=new Date() --> Create a time object and assign it to the current time;
B: var newdt=new Date(milliseconds) --> Create a time object and set the value of the object in milliseconds with the delay time of GTM;
C: var newdt=new Date(string) --> Assign a value to the newly created time object with a specific time string in a format that matches the Date object's parse method.
D: var newdt=new Date(year, month, day, hour, minute, second, millisecond) --> Assign values to objects in the order of year, month, day, hour, minute, second and millisecond.

Methods: to obtain the time; Set time; Format conversion

A: get the time

GetDate () -- gets the current full time;
GetYear ()-- gets the current year
GetMonths ()-- gets the current month
GetDay ()-- gets the current date and day
GetHours ()-- gets the current hour
GetMinutes ()-- gets the current minute
GetSeconds ()- gets the current seconds
GetTime ()- gets the current time in seconds
GetTimeZoneOffset - gets the current time zone offset information

B: set the time

Compare with the above, replace get with set, for example, getDate() --> SetDate ()

C: conversion method

ToGTMString () -- a string converted to a Greenwich mean time expression;
ToLocaleString ()-- converts to a string expressed in local time
ToString ()-- converts time to a string
Parse - read the time from a string that represents the time
UTC- returns the difference in milliseconds between Greenwich mean time and the specified time

Math mathematics:

Properties: note that properties in mathematical objects refer to reads

E (=2.7182) -- the base of the natural log.
Natural log of 10(=2.30259) -- natural log of -10;
Natural log of LN2(=0.69315)-- natural log of -2;
(= 3.1415926) -- PI PI
SQRT1_2(=0.7071)-- square root of 1/2
SQRT2(=1.4142)-- square root of 2
Log of 2e (=1.44269)-- log base 2 of E
LOG10E(=0.43429)-- log base 10 of E

Method: actually use of not much, depressed, all out

Sine of a -- sine of a
Cosine of a -- find the cosine of a
Tangent of a -- tangent of a
A sine of a -- find the inverse sine of a
Atan of a -- find the arc cosine of a
E to the a -- to the exponent of a
Log of a -- let's take the natural log of a
Pow of a, I -- a to the I power.
Round (a)-- round a
SQRT of a -- square root of a
Abs of a -- let's take the absolute value of a
Random ()-- take a random number
Max of a,b -- take the larger number
Min of a,b -- take a smaller number

Note: the arguments to the function are floating-point, and the arguments to the trig function are radians, not degrees

Built-in functions for JavaScript

Escape () vs. unescape() : encodes and decodes strings

Eval (string): used to perform an operation or statement represented by a string
For example, var a=0; Var str1 = a + = "a"; The eval (str1);

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

Note: instead of rounding Numbers, parseInt() cuts the ends

IsNaN (): the full E text is (is not a number), as the name implies to determine whether a string is a number, such as if(isNaN

Custom objects: there are two ways to initialize an object and to define an object with a constructor

A: initialize the object

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

B: the object that defines the constructor

Such as:
Function name (attribute 1, attribute 2... Properties of 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 the function name can be the same, but the function must be defined before the method calls the function, otherwise an error will occur

Creating a new instance of a custom function also USES the new statement.

Browser object

The window object: He belongs to the central level, the highest level of all objects, to put it bluntly, without him, you all have no fun;


Closed -- used to determine whether the window is closed;
Er -- store () method to open the parent window of the window;
Defaultstatus -- the information displayed in the status bar by default;
Status -- the information currently displayed in the status bar;
The Document, the Location, the History - is very important, later said in detail, such as if you don't want to, look here directly


Alert (text)-- a prompt message box pops up
Confirm (text)-- confirm message box, parameter is confirm message
Prompt (text,default)- prompt(text,default)-- the input dialog box pops up with prompt and default parameters

The document object: Include various features of the current page, such as title, URL, background, language, modification time, etc


Title -- document title
LastModified - the last time a file was modified
URL-- the corresponding page address of the document
Cookie-- used to create and obtain Cookie information
BgColor -- the background color of the document
FgColor - foreground of the document
Location -- save all the page address information of the document
Alinkcolor - activates the color of the connection
Linkcolor - the color of a link
Vlinkcolor - the color of a browsed link


Write (text)- writes text or tags to a document without breaking lines
Writeln (text)- writes a text or label to a document, breaking the line at the last character
()-- open a new document such as "address "," window name "," style"
Close ()-- close the current document

The Location object: Contains all page address information for the current document


Protocol -- communication protocol
Host -- the name of the WEB server where the page is located
Port -- the port number for server communication
Pathname -- the document's path on the server
Hash -- anchor tag information for page jumps
Searce -- information submitted to a server for search
Hostname -- hostname and port number separated by colon
Href -- complete URL address


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

History: This object contains URL information that was previously accessed

Property: length, which returns the number of urls

Related articles: