This article summarizes the use of array and string in javascript based on your own experience. We recommend this article to anyone who needs it.
I. Summary of array Methods
Will change the original array
The push and unshift Methods return the length. If the value is added, the length is returned. If the value is increased, other elements are returned.
Pop, shift returns this element
Reverse returns this element
Splice (start, deleteCount, addItem...), delete and add from the original array, return the deleted Array
Returns a new array without changing the original array.
Concat, join, slice (start, end)
Remember that the three are new arrays, and the others will change the original array.
Ii. Summary of the Sting Method
If the original value is not changed, a new String or other values are returned.
1. When the response is string.match(regexpwithout gnames and regexp.exe c (string), the result is the same.
If a packet is captured, the subscript is a substring that matches 0, and the subscript is the text captured by Group 1.
If the string contains the g ID, it will generate all the matching arrays (except for the capture group). For the regular exec, you can judge down step by step to determine whether it is null.
All lastindexes of reg are available.
2. string. slice (start, end), the end parameter is equal to the position of the last character you want To take + 1. If you want to get the nth character starting from position p, use string. slice (p, p + n)
String. substring is the same as array. slice.
3. Regular Expressions can be used for replacement or grouping.
String. split (separator, limit), limit can limit the number of segments to be split, and the regular expression has the same g
String. replace (searcdhValue, replaceValue), searcdhValue if the regular expression contains g, all the matches will be replaced. If not, only the first match will be replaced.
If it is a string, the value is replaced in the first place where it appears
Learning is a step-by-step process. It is only possible to make a qualitative breakthrough through continuous summarization and learning. Recently, we have been summing up some things about javascript, hope you and everyone can take another step.