Js--string, Date, Array object

Source: Internet
Author: User
Tags pow

/*
* String Object
Property length
Method
*/
The length property of the string
var StrL = "ABCDE";
document.write ("<br/>");
document.write ("attribute:" + strl.length);
Method of String
document.write ("<br/>");
document.write ("Method:" + strl.bold ());
document.write ("<br/>");
document.write (Strl.fontcolor ("Red"));
document.write ("<br/>");
document.write (Strl.fontsize (7));
document.write ("<br/>");
Sub sup subscript

document.write ("<br/>");
var str1 = "Hello";
var str2 = "World";
document.write ("String link:" + str1.concat (str2));
document.write ("<br/>");
document.write ("returns the specified position string, where no value returns null:" + str2.charat (0));
document.write ("<br/>");
document.write ("Returns the index of the specified position string, the value does not return-1:" + str2.indexof ("w"));
document.write ("<br/>");
var str3 = "a-b-c-d";
var arr1 = Str3.split ("-");
document.write ("Split method Cut, slice string, array:" + arr1.length);
document.write ("<br/>");
var STR4 = "ABCD";
document.write ("Replace replace, replacing a with E" + str4.replace ("A", "E"));
document.write ("<br/>");
document.write ("substr," + str4.substr (1, 2)),//BC 2-bit backward from 1th position
document.write ("<br/>");
document.write ("substring:" + str4.substring (1, 2)),//b from the beginning to the end of the first, does not contain the last person [

3 ways to create an array
var arr21 = [1, 2, 3];
var arr22 = new Array (3);
var arr23 = new Array (1, 2, 3);

/**js Array Object
concat ()
Join ()
push ()
Pop ()
reverse ()
*/
var arr11 = [1, 2, 3];
document.write (" document.write (arr11.length);
document.write ("<br/>");
document.write ("concat (): links to Arrays" + arr11.concat ());
document.write ("<br/>");
var arr12 = new Array (3);
Arr12[0] = "a";
Arr12[1] = "B";
Arr12[2] = "C";
document.write ("Join (): Splits an array with the specified character:" + Arr12.join ("-"));
document.write ("<br/>");
document.write ("push (): Adds an element at the end of the array and returns the new array length:" + Arr12.push ("D"));
document.write ("<br/>");
var arr13 = ["AAA", "BBB", "CCC"];
var arr14 = ["www", "QQQ"];
document.write ("Add an array with the push method in an array:" + Arr13.push (arr14));
document.write ("<br/>");
//Use push to add an array to the array, and he will add the array as a string to the array
for (var i = 0; i < arr13.length; i++) {
document.write (arr13[ I]);
document.write ("<br/>");
}

document.write ("<br/>");
var arr14 = ["Zhangsan", "Lisi", "Wangwu", "Zhaoliu"];
document.write ("Old length:" + arr14.length);
document.write ("<br/>");
document.write ("Pop () deletes the last element, and returns the last element:" + arr14.pop ());
document.write ("<br/>");
document.write ("New length:" + arr14.length);
document.write ("<br/>");
document.write ("New arr:" + arr14);

document.write ("<br/>");
document.write ("reverse (): Reverses the order in the array:" + arr14.reverse ());

/**date Object
toLocaleString: Convert dates to custom date formats
getFullYear: Get the current four-digit year
GetMonth: Get the current month, the return value is 0月-November, get the value +1
GetDay: Gets the current week, the return value is 0-6, Sunday is 0 indicates
GetDate: Get the current day, 1-31
GetHours: Get the current hour
Getminutes (): Get the current minute
Getseconds (): Gets the current seconds
GetTime (): Gets the number of milliseconds: the number of milliseconds that are returned is 1970-1-1 to the present: effect of processing cache with milliseconds (no cache) Example: www.baidu.com? Number of milliseconds
*/
var date = new Date ();
document.write ("document.write ("Local date format:" + date);//Gets the current time
document.write ("<br/>");
document.write ("converted to a custom date format:" + date.tolocalestring ());
document.write ("<br/>");
document.write ("Get the current year's method: getFullYear ():" + date.getfullyear ());
document.write ("<br/>");
document.write ("method to get the current month: GetMonth ():" + (Date.getmonth () + 1));
document.write ("<br/>");
document.write ("Get the current Week: GetDay ():" + date.getday ());
document.write ("<br/>");
document.write ("Get Current day: GetDate ():" + date.getdate ());
document.write ("<br/>");
document.write ("Get Current Hour: getHours ():" + date.gethours ());
document.write ("<br/>");
document.write ("Get Current minute: getminutes ():" + date.getminutes ());
document.write ("<br/>");
document.write ("Get Current Seconds: getseconds ():" + date.getseconds ());
document.write ("<br/>");
document.write ("Get milliseconds: GetTime ()" + date.gettime ());//Returns the number of milliseconds since 1970-1-1. Application scenario: The effect of processing the cache with milliseconds (no cache) Example: Www.baidu.com? Number of milliseconds

The/**math object is full of static methods, using Math. Method Name ();
Ceil (): Rounding up
Floor (): Rounding Down
Round (): Rounding
Random (): Randomly number
Max (x, y): Maximum value
Min (x, y): Minimum value
Pow (x, y): Power of X,
*/
document.write ("var mm=10.4;
document.write ("Ceil (): Rounded up:" +math.ceil (mm));
document.write ("<br/>");
document.write ("Floor (): Round Down:" +math.floor (mm));
document.write ("<br/>");
document.write ("round () rounded" +math.round (mm));
document.write ("<br/>");
document.write ("Random () stochastic" +math.floor (Math.random () *10));//Get 0-9 random numbers
document.write ("<br/>");
document.write ("Pow (x, y): X's Y Power:" +math.pow (2,5));

Js--string, Date, Array object

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.