JS built-in object string object

Source: Internet
Author: User

JS built-in objects

String object: A String object that provides properties and methods for manipulating a string.

Array object: A property and method for array manipulation.

Date object: A DateTime object that can obtain the system's datetime information.

Boolean object: A Boolean object, a Boolean variable that is a Boolean object. (No properties and methods are available)

Number object: Numeric object. A numeric variable is a numeric object.

Math object: A Mathematical object that provides properties and methods for mathematical operations.

Properties and methods for string objects

Length: Gets the lengths of the strings. Example: var len = strobj.length

toLowerCase (): Turns the letters in the string to lowercase. such as: Strobj.tolowercase ()

toUpperCase (): Converts the letters in a string to uppercase. such as: Strobj.touppercase ()

CharAt (Index)

Function: Returns a character that specifies the position of the subscript. If it is not found, an empty string is returned.

Syntax: Strobj.charat (Index)

Parameter: Index is the specified index number that returns a character based on the index number.

IndexOf ()

Function: Returns the index value of a substring in the original string (the lookup order is looked up from left to right). If not found, returns-1.

Syntax: Strobj.indexof (SUBSTR)

Parameter: substr represents a substring to find.

LastIndexOf ()

Function: Finds a substring in the original string, from right to left . If not found, return-1.

Syntax: Strobj.lastindexof (SUBSTR)

Parameters: Substr represents the substring to find.


Function: Returns a substring in the original string.

Syntax: Strobj.substr (startIndex [, length])

Description: Returns the length of a character from subscript startindex.


startindex indicates the starting index number of the lookup;

Length is optional and returns several characters. If omitted, always returns to the end.


Function: Returns a substring in the original string.

Syntax: strobj.substring (StartIndex [, EndIndex])

Description: Returns all characters from the startindex start index value to the Endindex end index value.


StartIndex: Represents the starting index value.

EndIndex: Optional, which represents the end index value. If omitted, all characters are generally returned to the end.

Tip: If you omit the second argument, the substr () and substring () results are the same.

Note: substring () The returned characters contain startindex the character at the Endindex, not including the character at the same place.


"ABCDEFGH". substring (0,5) = "ABCDE"

"Abcdefgh". substr (0,5) = "ABCDE"

"ABCDEFGH". substring (2,3) = "C"

"Abcdefgh". substr (2,3) = "CDE"

Split () : Converts a string to an array

Function: Cuts a string into several segments. returns an array .

Syntax: Strobj.split (partition number)

Parameter: The argument is a string of a split number. Divides the string into segments with the specified partition number.

Example: "A,b,c,d". Split (",") = arr["A", "B", "C", "D"]

JS built-in object string 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.