JS built-in objects, Date,string,array knowledge points

Source: Internet
Author: User
Tags array example time in milliseconds

1.Date

Common ways to process time and date in the data object:

(1) get current time : Example: Var d=new Date () return value is:

(2)get/setyear () Returns/sets the current year (two digits)

(3)get/setfullyear () : Returns/sets the current year (four digits)

(4) Get/setmonth (): Returns/sets the current month (0-11 0-month 11-12 months)

(5) Get/setdate (): return/Set Date, XX day (1-31)

(6) Get/setday (): Return/Set Week (0-6, 0: Sunday)

(7) Get/sethours () return/Set hour, 24-hour (0-23)

(8) Get/setminutes () returns/sets the number of minutes (0-59)

(9) Get/setseconds () returns/sets the number of seconds

(Ten) Get/settime () returns/sets the time in milliseconds: calculates the number of milliseconds from January 1, 1970 to the date the Date object refers to

(one) getmilliseconds () Gets the current number of milliseconds

() tolocaledatestrings () gets the current date

() tolocaletimestrings () get the current time

toLocaleString () Get the date and time
2.String
(1) CharAt (): Returns the character at the specified position, and the returned character is a string of length 1
Syntax: Stringsobject.charat (Index) (index: required, a number that represents a position in a string, that is, the character is subscript in the character set, and the method returns an empty string if the argument index is not in 0~string.length-1)

(2) Length: Calculates the length of the string

Syntax: stringsobject.length

(3) IndexOf (): Returns the position of the first occurrence of a specified string value in a string.

Syntax: stringobject.indexof (substring, startpos) (substring: Required, specifies the string value to be retrieved ; Startpos: Value is 0-stringsobject.length-1, if omitted, retrieved from the top of the string)

(4) substring (): A character used to extract a string intermediary between two specified subscripts.

Syntax: stringobject.substring (Starpos,stoppos) (Starpos: Start position, nonnegative integer; Stoppos: End position, if omitted, to end of string)

(5) substr (): Extracts a specified number of strings starting from the Startpos position from the string.

Syntax: Stringobject.substr (startpos,length) (stratpos: Start position; length: To extract the lengths of the string)

(6) Split:arr2=arr1.split ("split symbol");

3.Array

<1> three ways to define arrays

(1) var myarr=new Array ();

Myarr[0]= "";

......

(2) var myarr=new Array ("", "", "");

(3) var myarr=["", "", "" ";
Handling of <2> arrays
(1) Push: Adding elements from the end of an array
Example: Var arr=[1,2,3]; Arr.push (4); The resulting array is [1,2,3,4]
(2) Pop: Remove elements from the end of an array
Example: Arr.pop (); The resulting array is [2,3]
(3) Unshift: Adding elements from the head of an array
Example: Arr.unshift (4) The resulting array is [4,1,2,3]
(4) Sort: array elements sorted (string only) Arr.sort ();
Array of numbers (small to Large): Arr.sort (function (numi,num2))
{return num1-num2};
(5) Concat: Connection Array Example: Alert (Arr1.concat (ARR2));
(6) Join: instance var arr=[1,2,3,4] Alert (arr.join ('-')); The results are as follows: 1-2-3-4
(7) splice:1. Delete an array element at any location: syntax: Arr.splice (start position, delete length);
2. Insert an array from anywhere in the array: arr.splice (inserted position, 0, ' inserted element 1 ', ' inserted element 2 ',.....)

JS built-in objects, Date,string,array knowledge points

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.