String common methods:
Character substring (index start start position, end position end index) intercepted location does not contain the end position, a write-only parameter indicates the interception position from the beginning to the end
STR = var 'ABCDEFG';
str.substring (. 1) // give bcdefg str.substring (1,3) // bc obtained
when the negative input becomes a negative value 0, which is smaller as the start position
str.substing ( -1,1) => str.substring (0,1) // A
str.substring (. 1, -2) => str.substring (0,1) // A
slice (start index start position, end position index end) and substring substantially similar, the difference in argument is negative.
STR = var 'ABCDEFG';
str.slice (. 1) // bcdefg str.substring (l, 3) // BC
length of the input string by adding a negative time value
str.slice (-1) => str. Slice (. 6) // G
str.slice (. 1, -2) => str.slice (l, 5) // BCDE
str.slice (-2, -1) => str.slice (5,6) / / f
becomes 0 when the absolute value is greater than the length of the string
str.slice (-22) => str.substring ( 0) // abcdefg
second parameter is greater than the absolute value of the length of the string, returns'
substr (start position start index, end the need to return the number of characters)
STR = var 'ABCDEFG';
str.substr (. 1) // bcdefg str.substr (1,1) // B
length parameter string start adding a negative input, end is negative parameter becomes 0
str.substr (-1) => str.substr (. 6) // G
str.substr (-2, -3) // ''
the charAt (index) method returns the character at the specified index. If out of range (0 string length minus one) index value of an empty string.
STR = var 'ABCDEFG';
str.charAt (2) C //
the indexOf (String) String object back into the position of the first occurrence. If sub-string is not found, returns -1.
STR = var 'abcdefga'
str.indexOf ( 'A') // 0
str.indexOf ( 'H') // -. 1
lastIndexOf (String) flashback lookup
returns the String object position of the first occurrence. If sub-string is not found, returns -1.
STR = var 'abcdefga'
str.lastIndexOf ( 'A'). 7 //
Split (STR) is divided into a parameter string array
STR = var 'abcadeafg'
str.split ( 'A') // [ "", "BC", "de", "FG"]
the toLowerCase method returns a string, this string is converted into lowercase letters.
toUpperCase method returns a string of all the alphabetic characters are converted to uppercase.
match () - method retrieves the value specified in string, or to find one or more regular expression matching
search method returns the regular expression to find a position of the first character string matching content.
to replace the search string to match a regular expression, then instead of using a new matching string
Array common way
push to the array is added after the last return
unshift added to the array after the return to the front to add
After deleting the array returned shift process (from the front)
pop delete the last item in the array returned after treatment
reverse inverting Array Returns an array of processed
join array into a string
ARR = var [1,2,3,4,5], STR = arr.join ( '-');
the console.log (STR); // to 1--2--3--4--5 cutting parameters within the array join
console.log (arr); // [1,2,3,4,5 ] unchanged original array
slice (start, end) array taken (no end) from the start (start) to end
returns a new array, the original array unchanged
ARR = var [1,2,3,4,5], arr.slice new new = (2,4);
the console.log (new new); // [3,4-]
the console.log (ARR); // [ 1,2,3,4,5]
concat array merge
splice (start subscript number, ele1, ele2 ...) splice array
(1). a parameter from the parameter taken to fill a position similar to the above negative return str slice cut good array changes the original array
ARR = var [1,2,3,4,5];
the console.log (arr.splice (. 1)); // [2,3,4,5]
the console.log (ARR); // [. 1]
console.lgo (arr.splice (-1)) // [. 5]
(2). intercept two parameters (start position, number) returns an array of the original array change truncated good
ARR = var [1,2,3,4,5];
the console.log (arr.splice (l, 3)); // [2,3,4]
the console.log (ARR) // [l, 5 ]
arr.splice (0,1) => arr.shift ()
arr.splcie (arr.length-1,1) => arr.pop ()
(. 3). was added to increase the original array
var arr=[1,2,3,4,5];
console.log(arr.splice(1,0,13)); // []
console.log(arr); // [1,13,2,3,4,5]
(4).替换
ARR = var [1,2,3,4,5];
the console.log (arr.splice (1,2, 'A', 'B')) // [2,3]
the console.log (ARR); // [. 1, 'A', 'B', 4,5]
arr.splice (0,0,1) => arr.unshift (. 1);
arr.splice (arr.length, 0,1) => arr.push (. 1)
arr.forEach (item, index, array) {} traversal, each cycle of similar jquery
wherein the parameter item is the contents of the array, index its index, array represents an array itself
ARR = var [1,2,3,4,5];
arr.forEach (function (Item, index, Array) {
})
Map mapping method and usage similar forEach
var men=[
{'name':1,'age':12},
{'name':2,'age':22},
{'name':3,'age':33}
],
age=men.map(function(item){
return item.age;
})
rr.sort 排序
ARR = var [1,2,22,11,33,3,5,4];
the console.log (arr.sort ()) // [1,11,2,22,3,33,4,5]
by default sort method is ascii sorted in alphabetical order, rather than numbers we think are sorted by size
arr.sort (function (A, B) {return ab &})
ab & ascending descending ba
I think it is the most important foundation ~~
----------------
Disclaimer: This article is CSDN blogger's original article, follow the CC 4.0 BY-SA copyright "Hello My girl." agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/sslcsq/article/details/103858642