Summary 11th Day

Source: Internet
Author: User
Tags truncated

Today I learned a string object, an array object, a Date object.

String object:

Create a String object: The first: A string variable defined with single and double quotes then it is a string object

var variable name = "string"

The second type: Use the New keyword and the string () method to create

var variable name =new srting ()

Property: Stringobject (String object). Length Gets the total number of characters in the string!

Method: Stringobject.charat (Index) returns a specified subscript character; index: represents the specified subscript

Stringobject.indexof (substr) finds the position of the first occurrence of the string, and returns its corresponding subscript if found;

Returns 1 if the lookup is a "word" found in case the return is

The subscript of the first letter of the word; substr: the string to find

stringobject.substring) (Startindex[endindex]): Intercepts substrings from the original string; Statindex: Indicates the start of intercept subscript;

EndIndex: Optional If no write indicates that the original character has been intercepted from the beginning subscript

At the end of the string, if there is a write, the end of the subscript if you want to use the second parameter

Count so be sure to remember

                          

Stringobject.substr (Startindex[,length]) intercepts the substring from the original string; StartIndex: Indicates the start of intercept subscript; length: Optional If no write indicates that the end of the original string is truncated from the beginning of the subscript, if there is a write The table

Length of the truncated string

Stringobject.substring (Startindex[,endindex]) intercepts substrings from the original string; StartIndex: Indicates the start of intercept subscript; EndIndex: Optional If not written Represents the end of the original string from the beginning of the subscript;

Write indicates the end of the subscript; If you want to use the second parameter then be sure to add 1.

Stringobject.tolowercase () converts uppercase letters to lowercase

Stringobject.touppercase () converts lowercase letters to uppercase

Stringobject.split (Sep) divides a string into an array; Sep: represents the specified delimiter

Stringobject.replace (regular expression, character to replace) replace one string with another

Stringobject.localecompare (target) compares the order of two strings

Array object:

The first method: use [] to create an array

The second method: Use the New keyword and the array () method to create

Property:Arrayobject.length Gets the length of the array

Method:Arrayobject.shift () deletes the first element in the array and returns it

   Arrayobject.push () adds one or more array elements to the end of the array and returns the new length

arrayobject.join ([Sep])   merges an array into a string; Sep: Optional If this parameter is not filled in, it means to connect using the comma below the English language, and If there is a write, it is represented by the specified symbol Come in

Row connection

Arrayobject.reverse () flips the array

  Arrayobject.sort (sortby) sorting an array element

! If the method is called without parameters, the elements in the array are sorted alphabetically, more precisely, by the order in which the characters are encoded. To do this, you should first convert the elements of the array to a string, if necessary, for comparison.

! If you want to sort by other criteria, you need to provide a comparison function that compares two values and returns a number that describes the relative order of the two values. The comparison function should have two parameters A and B with the following return values:

If a is less than B, a value that is less than 0 is returned if a should appear before B in the sorted array.            If a equals B, 0 is returned. If a is greater than B, a value greater than 0 is returned.

Date object:

Create a Date object:

First: Use the new keyword with date () to create a parameter

Second: Use the new keyword with date () to create without parameters

Dateobject.getfullyear (): Get a 4-digit year

Dateobject.getmonth (): Get month Value: 0-11 0 means January 11 means December

Dateobject.getdate (): Gets the number of days to value: 1-31

Dateobject.gethours (): Gets the hour value: 0~23

Dateobject.getminutes (): Gets the minute value: 0~59

Dateobject.getseconds (): Gets the number of seconds to value: 0~59

Dateobject.getmilliseconds (): Gets the number of milliseconds to value: 0~999

Dateobject.getday (): Gets the value of one day of the week: 0-6 0 = Sunday

Dateobject.gettime (): Gets the time stamp obtained is from January 1, 1970 to present the millisecond number of GMT

Summary 11th Day

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.