Home > database >  string
string

Time:10-01

An array of
Concat ()
Add elements to the array and returns a new array, will not change the original array,

Let arr=,5,2,7,9,13,8 [3];
Let arr1=arr. Concat (2);
console.log(arr);//,5,2,7,9,13,8 [3]
The console. The log (arr1);//,5,2,7,9,13,8,2 [3];
The join (separator) converts all elements in the array to a string, and then together,
The separator in the returned string or a string of characters used to separate array element, it is optional, if this parameter is omitted, a comma as a separator,

Let arr=,5,2,7,9,13,8 [3];
The console. The log (arr. Join ());//3,5,2,7,9,13,8
The console. The log (arr. Join ("/"));//3/5/2 7/9/13/8
Pop ()
Delete a project, from array tail

Let arr=,5,2,7,9,13,8 [3];
Arr. Pop ();
console.log(arr);//,5,2,7,9,13 [3]
Push ()
Add an item to the end of the array,

Let arr=,5,2,7,9,13,8 [3];
Arr. Push (2);
console.log(arr);//,5,2,7,9,13,2 [3]
The reverse ()
In the original array reverses the order of the array elements,

Let arr=,5,2,7,9,13,8 [3];
Arr. Reverse ();
console.log(arr);//,13,9,7,2,5,3 [8]
The shift ()
Remove the head element of an array of arrays head,

Let arr=,5,2,7,9,13,8 [3];
Arr. Shift ();
console.log(arr);//,2,7,9,13,8 [5]
Slice ()
Returns a new array after capture,
The first parameter
Array segments at the beginning of the array subscript, if it is negative, it declares from the array will be backdated to the tail of the position, that is to say, 1 refers to the last element, - 2 refers to the penultimate element, and so on,

The second parameter
Array fragments after the end of an element of an array subscript, if you don't specify this parameter contains all from the first parameter to the end of the array elements, if this parameter is negative, will be backdated to the tail of the elements from an array and

Let arr=,2,3,4,5,6,7,8,9,10 [1];
//a parameter
Let I=arr. Slice (3);
console.log(i);//[4, 5, 6, 7, 8, 9, 10]
console.log(arr);//[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//two parameter
Let j=arr. Slice (2, 6);
The console. The log (j);//[3, 4, 5, 6]
console.log(arr);//[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Let I=arr. Slice (3);//equal to slice (7)
console.log(i);//[8, 9, 10]
Let j=arr. Slice (- 6-2);//equal to slice (4, 8)
The console. The log (j);//[5, 6, 7, 8]
Let k=arr. Slice (2, 6);//equal to slice (8, 4)
The console. The log (k);//[]
Sort ()
Array elements on the original array sort, in the order ASCLL yards in ascending order

Let arr=[0,12,3,7-12, 10];
The console. The log (arr. Sort ());
//[- 12, 0, 12, 23, 3, 7]
Compare the size so to write
Arr. Sort ((a, b)=& gt; A - b)
Splice (); You can add or remove elements to an array and returns the modified array, will change the original array

Let the STR=,4,2,5,3 [1];
The first value: the starting position, the second value: delete the number of elements, the third value add elements
STR. Splice (2, 1, "hello");//[1, 4, "hello", 5, 3]
ToLocaleString ()
Convert an array to a localized string,

Let arr=,5,2,7,9,13,8 [3];
The console. The log (arr. ToLocaleString ());//3,5,2,7,9,13,8
The toString ()
Convert an array to a string,

Let arr=,5,2,7,9,13,8 [3];
The console. The log (arr. ToString ());//3,5,2,7,9,13,8
Unshift ()
The head insert an element in the array,

Let arr=,5,2,7,9,13,8 [3];
Arr. Unshift (2)
console.log(arr);//,3,5,2,7,9,13 [2]
String
1, the search string location (space is a character) returns a subscript

Let the STR="qwer easdfg er trew er".
STR. IndexOf (" w ");//returns the character first appeared subscript
STR. LastIndexOf (w);//returns the character was last seen subscript
2, remove Spaces, returns a new string

Let the STR="qwer easdfg er trew er".
STR. TrimLeft ();//remove left blank
STR. TrimRight ();//remove the right space
STR. The trim ();//remove Spaces, does not remove the middle of the
3, repeated strings and returns a new string

Let the STR="qwer easdfg er trew er".
STR. Repeat (repetition);
4, find a character matches, return true and false

Let the STR="qwer easdfg er trew er".
STR. StartsWith (" z "); Query to character matches the
STR. EndsWith (" a "); Query the end character matches the
Let the STR="Hello World";
The console. The log (STR. Includes (" l "));//true
The console. The log (STR. Includes (" M "));//false
5, access to specific characters
CharAt () accepts a numeric parameters, and find out the elements of the subscript

Let the STR="Hello World";
The console. The log (STR. CharAt (1));//e
The console. The log (STR. CharAt (' a '));//H because is converted to a 0
CharCodeAt () accepts a numeric parameters, and find out what is the character encoding the subscript

Let the STR="Hello World";
The console. The log (STR. CharCodeAt (1));//101
The console. The log (STR. CharCodeAt (' a '));//72
6, string manipulation
Concat () string concatenation, using few general use operator +

Slice slice of an array of () and () method is similar to accept one or two parameters, the interception of string
If it is negative, and the length of the string together

Let the STR="Hello World";
Let str2=STR. Slice (2);
Let str3=STR. Slice (2, 7);//not including 7
The console. The log (STR);//Hello World
The console. The log (str2);//llo World
The console. The log (str3);//llo W
Str1=STR. Slice (2, 3);//equal to slice (2, 8)
Substr () and slice () method is similar to
The first value and the length of the string together, the second value of the negative transformation of 0

Let the STR="Hello World";
Let str1=STR. Slice (2);
Let str2=STR. Substr (2);
The console. The log (str1);//llo World
The console. The log (str2);//llo World
Str1=STR. Slice (2, 7);//not including end position 7
Str2=STR. Substr (2, 7);//returns the number of characters to
The console. The log (str1);//llo W
The console. The log (str2);//llo Wor
Str2=STR. Substr (2, 3);//is equal to the substr (2, 0)
The substring () to extract the string
To transform all negative values of 0, since the smaller number of larger number of end

Let the STR="Hello World";
Let str1=STR. Slice (2);
Let str2=STR. Substr (2);
Let str3=STR. The substring (2);
The console. The log (str1);//llo World
The console. The log (str2);//llo World
The console. The log (str3);//llo World
Str1=STR. Slice (2, 7);//not including end position 7
Str2=STR. Substr (2, 7);//returns the number of characters to
Str3=STR. The substring (2, 7);//not including end position 7
The console. The log (str1);//llo W
The console. The log (str2);//llo Wor
The console. The log (str3);//llo W
Str3=STR. The substring (2, 3);//equal to the substring (2, 0) is equal to the substring (0, 2)
7, convert the string case
There are four methods: toLowerCase (), toLocaleLowerCase (), toUpperCase (), toLocaleUpperCase ()
nullnullnullnullnullnullnullnullnullnullnullnullnullnull