JavaScript string, Date, number, Math, array object day0912

Source: Internet
Author: User

String object:

How to create an object:

One: var str=new string ("string content");

Two: var str= "string content";

Common methods for string objects:

Anchor () Production anchor point
Blink () Adding blink tags to elements
CharAt () returns the character at the specified index position.
charCodeAt () returns an Integer that represents the Unicode encoding of the character at the specified position.
FontColor () places an HTML <FONT> tag with a COLOR attribute on both ends of the text in a String object
IndexOf () returns the character position of the first occurrence of a substring within a string object
Italics () places the HTML <I> tag at both ends of the text in a String object.
Link () places an HTML anchor with an HREF attribute on both ends of the text in a String object.
Replace () returns the copy of the string after the literal substitution based on the regular expression
Split () cut
SUBSTR () intercepts the substring,ss = s.substr(12, 5);  // Gets a substring. The first argument is the character that starts the Intercept, the second argument is the length of the truncated string

toUpperCase () Turn capital
toLowerCase Turn lowercase


Date object:

Common methods:

GetDate Method | GetDay Method | getFullYear Method | GetHours Method | Getmilliseconds Method | Getminutes Method | GetMonth Method | Getseconds Method | GetTime Method | getVarDate Method | GetYear Method | SetDate Method | setFullYear Method | Sethours Method | Setmilliseconds Method | Setminutes Method | Setmonth Method | Setseconds Method | SetTime Method |setyear Method | toLocaleString method

Realize:

var date=new date ();//Gets the current system time
document.write ("Current system time:" +date+ "<br/>");
document.write ("Year:" + date.getfullyear () + "<br/>");
document.write ("Month:" + (Date.getmonth () +1) + "<br/>");
document.write ("Day:" + date.getdate () + "<br/>");
document.write ("When:" + date.gethours () + "<br/>");
document.write ("Points:" + date.getminutes () + "<br/>");
document.write ("seconds:" + date.getseconds () + "<br/>");

document.write ("Current time is:" +date.tolocalestring ());


Number object:

How to create an object:

One: var variable = new Number(数字)

Two: var variable = number;

Common methods:

ToString () Converts a number to a string in the specified binary form.
ToFixed () specifies that the decimal place is reserved, and that it also has rounding functionality.

Realize:

var num=10;
document.write ("Binary:" +num.tostring (2));

var num1=3.1486;
document.write ("Keep two decimal Places" +num1.tofixed (2));


Common methods for Math objects:

Ceil rounding up
Floor () Rounding down
Random () Stochastic number method//The pseudo-random number generated is between 0 and 1 (including 0, excluding 1),
Round rounded to return the nearest integer to the given numeric expression.

Realize:

document.write ("Rounding:" +math.round (3.74) + "<br/>");//return 4

document.write ("Rounding Up:" +math.ceil (3.74) + "<br/>");
document.write ("Rounding Down:" +math.floor (3.74) + "<br/>");


Array object:

How to create:

Mode 1:
var variable name = new Array (); Creates an array of length 0.
Mode 2:
var variable name = new Array (length) creates an array object of the specified length.
Mode 3:
var variable name = new Array ("Element 1", "Element 2" ...); An object that creates an array of array-specified elements.
Mode 4:
var variable name = ["Element 1", "Element 2" ...];

Common methods:

Concat Method | Join Method | Pop Method | Push Method | Reverse Method | Shift Method | Slice Method | Sort Method | Splice Method | toLocaleString Method | ToString Method | Unshift Method | ValueOf method


Realize:

var arr=new Array ();
document.write ("Length of the array:" +arr.length+ "<br/>");

var arr1=new Array (5);

var arr2=new Array ("Zhang San", "John Doe", "Harry");

var arr3=["Zhang San", "John Doe", "Harry"];


var arr=new Array ("Zhang San", "John Doe", "Harry");
var arr1=new Array ("Chen Liu", "Zhao Qi");
var newarr=arr.concat (ARR1);
document.write ("a new array element after the two array elements are concatenated:" +newarr+ "<br/>");
Newarr.reverse ();
document.write ("The array element after the new array is reversed:" +newarr+ "<br/>");
Newarr.push ("Wang Ba");
document.write ("The array element after adding a new element is:" +newarr+ "<br/>");
Newarr.splice (2,2, "haha", "hehe");
document.write ("Delete the element from index value 2, delete the number of elements 2, and insert the new 2 elements after the array element is:" +newarr+ "<br/>");
document.write (newarr.length);



JavaScript string, Date, number, Math, array object day0912

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.