JavaScript Basic Learning 20 Q (c)

Source: Internet
Author: User

1. The traversal string does not have to be equal to using the array substitution (performance optimization) substring into the array join concatenation, + "" instead of ToString.
2. String three main operations: (1) str.indexof () only find the first keyword from position 0 to find

IndexOf ("keyword", "from"), lastIndexOf ("keyword", "from") [two traversal methods index return results]

(2) Str.slice (start,end+1) [Support positive and negative parameters], str.substring () usage is the same as slice only does not support negative parameters, Str.substr (start,count)
(3) Str.split ("delimiter", count) split string
3. Loop traversal keyword: var ha = "The goddess said she would come." I hastily tidied up the room, she said she did not come, I said I grass. "
var index =-1;
while (index = Ha.indexof ("I-grass", index + 1))! =-1) {
Console.log ("keyword found in the" + Index + "location");
}
4. Character Type Unicode range
Digital 0-9:48-57; uppercase letter a-z:65-90; lowercase letter a-z:97-122; Kanji: 19968-40869
5. Pattern matching: You can set the rules for finding replacements use pattern matching whenever you find a keyword that may change
Definition pattern:/keyword/mode I means ignore case g means global substitution
6.match () Gets the contents of all keywords cannot determine the location of the keyword. Length (not found returns null first if judged)
7. Regular Expressions: Handling string formatting with what: Rules for characters appearing in strings
When: find, replace keyword, verify string format
1. Select symbol: [All alternate characters], choose one more, one [] for one character
2.[^ Alternate character] except for the alternate character ^ must be placed in the first position or become a normal character
3.-symbol alternate character continuous range 1-9[a-za-z]
4. Predefined character set: \d-->[0-9], [a-za-z0-9_]-->\w (alphanumeric underscore), null character-->\s (can be a space tab)
5. If a special symbol appears in the rule, turn it into the original
6. Point. Represents any character
7. Quantity Word: quantifier {min,max}{num}: Fixed length {min,} at least for preceding character occurrences
8. Special quantifiers: +: At least once more unlimited *: Optional: No Limit the number of occurrences? : dispensable: Me? Go (one at a time)
9. () grouping, changing the pattern matching order
ID Number: \d{15} (\d{2}[0-9xx])?
Mobile number: (\+86)? \s*1[34578]\d{9}
10.^: The beginning of the entire expression indicates what to start with
11.$: The end of the entire expression indicates what ends with
12.? =x: Pre-sentence what is immediately followed by a character,?! X: Pre-sentencing the previous character is not immediately followed by what
8.RegExp object: specifically encapsulates a regular expression, invoking the API
Regexp.test ("checked string") returns Boolean type True False
var arr=regexp.exec ("content found") find the location and content of the keyword:
arr[0]= "Content found" Arr.index: Location
9. About Find: Only determine if there is or only find location: Str.indexof () Str.search (regular expression support)
Find only keyword content: Str.match ()
Both position and content: Regexp.exec ()
10. Get all <a href= "" ></a> regular <a (. +? ) href=[' "] (. *?) [‘"] (.*?) >
11. Regular expression: greedy mode. * OR. + defaults to match the entire string, then narrow the range.
Lazy mode: (. *?) or (. +?) Start with the first character and scale back
12. Remove part of the regexp from the content that matches the regular expression. $n $n is the nth parenthesis group starting from 1
Must be called with the RegExp object
13.str.split (/Regular expression/) str.replace (/Regular expression/) Str.match (/Regular expression/) Str.search (/Regular expression/) support regular expressions
14.str.trim () removes whitespace at the beginning of the string, without removing the first trim to the input string
IE8 does not support trim custom trim methods
15.String Summary: All APIs are to be caught with variables ....
16.Math type: All mathematical calculations math cannot be instantiated cannot be new
API:Math.PI math.round (num) rounded math.ceil (num) rounding up Math.floor (num) down rounding Math.pow (base, Power) math.sqrt (x) math.abs (num) Take absolute value
Math.max (value 1, value 2 ...) Math.max.apply (Math,arr)--to find a maximum value in an array

17.math.floor. ((Math.random () *max-min+1) +min) Random integer
18.Date object: Encapsulates a point-in-time data that provides API creation for time-date objects var date=new date ()
The date object is stored in the number of milliseconds from January 1, 1970 00:00:00 to the present
Api:1. Each component has a pair of get ()/set () methods: Gets the Set component value
2. Name: Month and day no s when seconds have s
3. Value assignment except the day of the month the rest is from 0 to 1 end
Month Value plus one correction assignment minus one correction
The week was starting in Sunday.
19. Date Calculation: Two-date subtraction to get the number of milliseconds
Time to add and subtract: Date.gettime () +5*60*1000
Do not change the original time object can only be accurate to the number of days
Arbitrary component calculation: Remove component calculation set go back
getFullYear Avoiding the Millennium bug
SETXXX () directly modify the original Date object automatically adjust the binary
20. Date format conversion API custom format
Number object: With a new reference type variable without a value type conversion num.tofixed (n) returns a string
Math.Round (num) Returns a numeric type that can only be rounded

JavaScript Basic Learning 20 Q (c)

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.