Home > Web Front-end > JS Tutorial > body text

Summary of array and string methods in JavaScript_Basic knowledge

WBOY
Release: 2016-05-16 16:29:52
Original
1569 people have browsed it

1. Summary of array methods

will change the original array

push and unshift methods return length. If the value is increased, length is returned, otherwise the element is returned

pop,shift returns the element

reverse returns the element

splice(start,deleteCount,addItem...), deletes and adds from the original array, and returns the deleted array

The original array will not be changed and a new array will be returned

concat,join,slice(start,end)

Remember these 3 return new arrays, the others will change the original array

2. Summary of Sting’s methods

No changes are made to the original value, but a new String or other value is returned.

1. What needs to be remembered is that the results of string.match (regexp without g) and regexp.exec(string) are the same.

If there is a capture group, the subscript is 0 matched substring, and the subscript is 1 group 1 captured text

If marked with g, string will generate an array containing all matches (except the capture group); with regular exec, you can judge it step by step to determine whether it is null.

Reg’s lastIndex is available.

2. string.slice(start,end), the end parameter is equal to position 1 of the last character you want to get. If you want to get the nth character starting from position p, use string.slice(p,p n)

The string.substring method 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 fragments to be split, the same as regular expression without g

string.replace(searcdhValue,replaceValue), if searcdhValue is regular with g, it will replace all matches, if not, only the first match will be replaced.

If it is a string, the value is replaced at the first occurrence

Learning is a step-by-step process. Only by constantly summarizing and learning can you achieve a qualitative breakthrough. I have been summarizing some things about JavaScript recently. I hope that I and everyone can reach a higher level.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template