Summary of array and string methods in javascript _ basic knowledge

Source: Internet
Author: User
Tags string methods
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.

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.