Method Summary of array and string in JavaScript _ basics

Source: Internet
Author: User

A summary of the method of array

Will change the original array

Push, Unshift method, return length. Added is worth the return length, the other returns that element

Pop,shift returns the element

Reverse returns the element

Splice (Start,deletecount,additem ...), removed and added from the original array, returns the deleted array

Will not change the original array, return the new array

Concat,join,slice (Start,end)

Remember that these 3 are returned to the new array, others will change the original array

Ii. Summary of the methods of sting

Does not change the original value, it returns a new string or other value.

1, it is necessary to remember that String.match (RegExp without G) and regexp.exec (string) the same result.

If you are grouping with captures, subscript 0 matched substrings, subscript 1 grouped 1 captured text

If marked with G, String generates an array that contains all the matches (except for the capture groupings); The regular exec, which can be judged by step down, is not null.

Reg has all the lastindex.

2, String.slice (start,end), the end parameter is equal to the last character you want to take position +1, if you want to start from position p of the nth characters, use String.slice (p,p+n)

String.substring and Array.slice methods.

3, for the replacement or grouping can be used regular

String.Split (separator,limit), limit can limit the number of fragments to be divided, just as there is no G

String.Replace (Searcdhvalue,replacevalue), searcdhvalue with G, replaces all matches, and if not, replaces only the first match.

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

Learning is a step-by-step process, Non-stop Summary, Non-stop Learning, will have a qualitative breakthrough, has recently been summing up some of the things about JavaScript, I hope that they and everyone can be a step up.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.