About the JS Date object mathematical object, the string object commonly used methods:

Source: Internet
Author: User
Tags square root

 
Common methods for String objects///////////////////////indexOf (), getting characters in a string The first occurrence of the position (from zero)//LastIndexOf (), the position of the last occurrence of the character in the string/var str = ' Helloword ';//var index = str.indexof (' o ');//var = s Tr.lastindexof (' h ');//Console.log (index),//Console.log (last),//Split (), split the string into an array by delimiter//parameter 1: delimiter, according to what delimiter to split// Parameter 2: Optional, limited to several elements//var str = ' www.baidu.com ';//var arr = str.split ('. '); /Console.log (arr);//replace (A, B) replaces a with b//var str = ' hellowordl1234 ';//var reg = ' 1234 ';//var result = Str.replace (Reg, ‘!‘);/ /Console.log (Result),//charat (index), looks for the character at index (//var str = ' hellow ');//var a = Str.charat (4);//4 index position character// Console.log (a);//Slice (start,end), intercept from start, intercept to end position/var str = ' Baidu ';//var result = Str.slice (0,2);// Console.log (result);//substr (start,length), intercept from start position, intercept length/var str = ' Qinghui ';//var result = Str.substr ( 0,4);//Console.log (Result),//toLowerCase (), convert string to lowercase//touppercase (), converts string to uppercase//var str = ' BaiDu ';//var upper = Str.touppercase ();//var lower = Str.tolowercase ();//Console.log (upper)//Console.log (lower); Common methods of mathematical objects//////////////////Math.Abs () Calculate absolute The value/var num = -100;//var result = Math.Abs (num),///Console.log (Result),//Math.ceil (), rounding up integers regardless of the number of decimals after the decimal point, will go into a whole//var num = 123.001;//var result = Math.ceil (num);//Console.log (result);//Math.floor (), take integer down//var num = 123.99;//var result = Math.floor (num);//Console.log (Result),//Math.Round (), rounded rounding//var num = 123.4;//var result = Math.Round (num);//Cons Ole.log (result);//Math.max (), calculates the maximum//Math.min (), calculates the minimum value/var max = Math.max (100,200,220);//var min = math.min ( 100,200,220);//Console.log (max);//Console.log (min);//Math.pow (x, y) get X "power"//var result = Math.pow (2,3);// Console.log (result);//MATH.SQRT (NUM) obtains the square root of num/var result = math.sqrt (144);//Console.log (result);//Math.random () take A random number between 0-1//var random = Math.random ();//conSole.log (random); Date Object Common method//////////////////////Date object provides the following methods to obtain the month day, time division seconds: getFullYear, GetMonth (), GetDate (), getHours (), getminutes (), getseconds ()///Get Date object: new Date ()//var odate = new Date ( )////Get date, Time//var year = Odate.getfullyear ();//var month = Odate.getmonth () +1; The value is from 0-11 to see the number, 0 is January ...//month = month<Ten? ' 0 ' +month:month;//var day= Odate.getdate ();//var hour= Odate.gethours ();//var minute= Odate.getminutes ();//var second= Odate.getseconds ();//// write to Body in//document.write (' Current time: ' +year+ '-' +month+ '-' +day+ ' &nbsp;&nbsp;&nbsp; ' +hour+ ': ' +minute+ ': "+second)////getday () Get Day of the Week//var odate= newDate ();///Weekday//var week= Odate.getday ();//return value between 0-6, 0 for Sunday//Console.log (week),//toLocaleString (), convert Date object to cost time format//var odate= newDate ();//var a= Odate.tolocaledatestring ();//document.write (a);

Common methods of JS date objects, common methods of mathematical objects, common methods of String objects

About the JS Date object mathematical object, the string object commonly used methods:

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.