Javascript method summary of array and string

  • 2020-03-30 04:25:00
  • OfStack

1. Method summary of array

It's going to change the original array

Push, unshift method, returns length. Increasing the value returns the length, and the other returns the element

Pop,shift returns the element

The reverse returns that element

Splice (start, deleteCount, addItem...). , delete and add from the original array, and return the deleted array

Does not change the original array, returns the new array

Concat, join, slice (start, end)

Remember that these three return a new array, and the others change the original array

Ii. Method summary of Sting

Instead of changing the original value, return a new String or some other value.

1. Remember that the result of a string.match(regexp without g) is the same as that of regexp.exec(string).

If there is a capture group, substring with subscript 0 to match, subscript 1 to group 1 to capture the text

If labeled g, string generates an array that contains all matches (except the capture group). Regular exec, step by step can go down the judgment, the judgment is null.

Reg has lastIndex.

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 the NTH character from position p, use string. Slice (p,p+n)

String.substring is the same as array.slice

3. Regex can be used for substitution or grouping

String.split (separator,limit),limit can limit the number of segments divided, regular has no g

String. The replace (searcdhValue replaceValue), searcdhValue regular if g, will replace all of the match, if not only replace the first match.

If it is a string, the value is replaced where it appears first


Related articles: