JAVASCRITPT string manipulation

Source: Internet
Author: User

Operation of the string:

Length: str.length;

Subscript: str[1];

Returns the character of a position: Str.charat (); Where to look in parentheses.

return character encoding: Str.charcodeat (); Where to look in parentheses.

return character: String.formcharcode (,); There are multiple write codes in parentheses

Returns a character position (left → right): str.indexof (); Write a character in parentheses not found return-1

(' AA ', 5)//start looking for AA from 5th position, negative for second parameter, as 0

Returns a character position (right → left): str.lastindexof ();

Intercept string: str.substring (); (0,5) from 0 to 5; (5,0) from 0 to 5; ( -2,5) from 0 to 5

: Str.slice (); (0,5) from 0 to 5; (5,0) not found; ( -2,5) second-to-last

Split string: Str.split (); (‘.‘) Take. To divide, return an array; the second parameter is length

Convert to uppercase: Str.touppercase ();

Convert to lowercase: str.tolowercase ();

Definition: var arr = [n/a]; var arr = new Array (No.);

Array Length: arr.length//readable writable

Added value: Arr.push (); Added later, returns the array length

Arr.unshift (); Previous add, return array length

Deleted: Arr.pop (); Delete the last one of the arrays, return the one that was deleted

Arr.shift (); Delete the first of the array, return the deleted

Splice:arr.splice (); (0,1); Delete 1 from the No. 0 bit and return the deleted one

(0,1, ' a '); Replace the first bit of the beginning of the No. 0 bit with ' a ',

(0,0, ' a '); Add ' A ' after the No. 0 bit

Sort: Arr.sort (); Sort by character encoding

function parameters

Reverse can be used reverse

Two array splicing: Concat (); Arr1.concat (ARR2)

Changed to String: Jion (); Arr.jion (' a ') to string A as a boundary character

JAVASCRITPT string manipulation

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.