Common JS functions

Source: Internet
Author: User

Escapse () encoding function
Escape ("(") =%28

Unescape () decoding function
Unescape ("%29") =)

eval () evaluation function
Eval ("one") = 11

IsNaN () numeric judgment function = = is not a number
IsNaN (0) = False
IsNaN ("a") = True
IsNaN (NULL) = False
IsNaN (undefined) = True

Parseint () turns into an integer function
parseint ("a") = 12

Parsefloat () turns into floating point number
Parsefloat ("12.3"). ToFixed (2); = 12.30


Array
var str = new Array ();
var str = new Array ([5]);
var str = new Array (+/-);

var = new Array (S1);
var s2 = new Array (3,2,1);

Concat () combines multiple arrays into a new array
var s3 = S1.concat (S2);
S3 = [1,2,3,3,2,1]
Only change S3, not change S1

Join () array elements are combined into a string, separated by specific characters
var S4 = S1.join ("-");
S4 = "the"

Split () Convert string to array
var S5 = S4.split ("-");
S5 = ["1", "2", "3"]

Shift () removes the first element of the array
S1.shift () = [2,3]

Pop () removes the last element of the array
S1.pop () = [+]

Push () puts an element into an array
S1.push (4) = [1,2,4]

Reverse () reversal
S1.reverse () = [4,2,1]

Slice () introduces the contents of the array into a new array, the original array is unchanged
S1.slice (1) = [2,1]

ValueOf () Get array contents
s1.valueof () = [2,1]

Boolean Object
1) If the conversion value is null, undefined, 0, and false are converted to logical values false
2) The rest is turned into true
var a = new Boolean (NULL) = False
var B = new Boolean (true) = True

ToString ()
A.tostring () = "false"

ValueOf ()
B.valueof () = True

Date Object
var sysdate = new Date ()
Sysdate.getyear ();
Sysdate.getfullyear ();
Sysdate.getmonth (); 0-11
Sysdate.getdate (); 1-31
Sysdate.getday (); Day of the week 0-6
Sysdate.gethours (); 0-23
Sysdate.getminutes (); 0-59
Sysdate.getseconds (); 0-59
Sysdate.getmilliseconds (); Milliseconds for a specific day 0-999
Sysdate.gettime (); Numeric value for a specific date

Mathematical functions
Math.ceil (1.22) = 2
Math.floor (1.22) = 1
Math.Round (1.22) = 1

Math.ceil (1.52) = 2
Math.floor (1.52) = 1
Math.Round (1.52) = 2


String Object
var str = new String ("ABCD");
str = = String {0: "A", 1: "B", 2: "C", 3: "D", length:4}

Anchor () Anchor Point
Str.anchor ("cc") = "<a name=" CC ">abcd</a>"

Fixed () fix word
Str.fixed () = "<tt>abcd</tt>"

FontSize ()
Str.fontsize (7) = "<font size=" 7 ">abcd</font>"

Search ()
Str.search ("b") = 1

Window Object Format
You need to label the window in front, and in many advanced applications, you can use a different alias instead of window
Example: When the system contains more than one size window
Opener: Indicates that the current window is open
Parnet: Represents the parent window of the upper frame
Self: Represents the currently active window
Top: Represents the topmost window

Closed: Determines whether the window is closed, the return value is a Boolean value
Status: Temporary information that represents the Status toolbar
Location: Contains information about the current URL
Parent: Represents the containing current window or frame group
Toolbar: The toolbar that represents the browser

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.