JS Common functions

Source: Internet
Author: User
Tags local time natural logarithm square root

Arithmetic operations in JS

1Math.pow (2,53)//= 9.,007,199,254,740,99e,+15:2 of 53 power2Math.Round (. 6)//= 1.0: Rounding3Math.ceil (. 6)//+ 1.0: Rounding up4Math.floor (. 6)//+ 0.0: Rounding down5Math.Abs (-5)//= 5: Absolute value6Math.max (x, Y, z)//returns the maximum value7Math.min (x, Y, z)//returns the minimum value8Math.random ()//generates a pseudo-random number greater than or equal to 0 less than 1.09Math.PI//π: PiTenMath.e//e: base of natural logarithm OneMATH.SQRT (3)//square root of 3 AMath.pow (3, 1/3)//Cubic root of 3 -Math.sin (0)//Trigonometric Functions: Math.Cos, Math.atan, etc. -Math.log (10)//Natural logarithm of 10 theMath.log (+)/MATH.LN10//logarithm with base 100 of 10 -Math.log (/MATH.LN2)//logarithm with base 512 of 2 -Math.exp (3)//three power of e

JS Date and Time

1 varthen =NewDate (2011, 0, 1);//January 1, 20112 varlater =NewDate (2011, 0, 1, 17, 10, 30);//the same day, local time 5:10:30pm,3 varnow =NewDate ();//Current date and time4 varelapsed = Now-then;//Date Subtraction: Calculates the number of milliseconds in a time interval5Later.getfullyear ()// +/-6Later.getmonth ()//+ 0: Month counting starting from 07Later.getdate ()//+ 1: Number of days to count starting from 18Later.getday ()//= 5: Get day of the week, 0 for Sunday, 5 for Monday9Later.gethours ()//= = local time 17:5pmTenLater.getutchours ()//use UTC to denote hours, based on time zone

JS string processing

1 vars = "Hello, world"//Define a string2S.charat (0)//= "h": first character3S.charat (s.length-1)//= "D": Last character4S.substring (1,4)//= "ell": 2nd to 4th character5S.slice (1,4)//= "ell": Ibid .6S.slice (-3)//= "Rld": last three characters7S.indexof ("L")//+ 2: Position of the first occurrence of the character L8S.lastindexof ("L")//= 10: The last occurrence of the character L9S.indexof ("L", 3)//+ 3: The position of the first occurrence of the character L at position 3 and afterTenS.split (",")//= = ["Hello", "World"] split into substrings OneS.replace ("H", "H")//= = "Hello, world": Full character substitution AS.touppercase ()

JS Common functions

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.