All the methods of String.prototype JavaScript

Source: Internet
Author: User
Tags truncated

All the methods of JS string Formcharcode:
String.formcharcode (";>>>>>>") "7"
The Unicode code returns the corresponding string. CharAt:
var str= "Hello World"; Str.charat (0);
>>>>> "H"; returns the corresponding string by index, the range is (0~string.length-1), and an empty string is returned when the index value is not in this range. charCodeAt:
var str= "Hello World"; Str.charcodeat (0); >>>>>104 (number);
The Unicode code of the corresponding character is returned by index, and the effect and usage are the same as the Charat, the range is (0~65535), and when the index is not in range, the result returns NAN;CODEPOINTAT: The Unicode code that returns the corresponding character by index. As with charCodeAt, the result returns UNDEFINED;CONCAT when the index is not in range:
var str= "Hello",    str2= "World"; var str3=Str.concat (str2); >>>>> "HelloWorld";
Merge two string endswith:
var str= "Hello World"; Str.endswith ("D"); >>>>>True
Whether to end with the string of the query, the return value is a Boolean value. Includes:
var str= "Hello World"; Str.includes ("he"); >>>>>>truestr.includes ("HL"); >>>>>>false
Whether the query contains substrings, the return value is a Boolean value. IndexOf:
str= "Hello World"; Str.indexof ("L"); >>>>>>2str.indexof ("z"); >>>>>>-1
A query string that returns the first query to the index value, if there is no queried value, returns -1.LASTINDEXOF:
var str= "Hello World"; Str.lastindexof ("L"); >>>>>>9Str.laseindexof ("ll"); >>>>>>2
A query string that returns the index value of the last query and, if there is no value for the query, returns -1.localecompare: Specifies that the function takes the collation provided by the underlying operating system. Match
 var  str= "Hello World" ;str.match ( ' Hello '  >>>>>> "Hello" str.match (/l+/ g);  >>>>>>[' ll ', ' l '  var  Str= "<input value={wwwww} type={222222}/>"  var  arr=str.match (/{(\w+)}/ >>>>>>[' {wwwww} ', ' wwwww '  for  (var  i in   ARR) Console.log (i);  >>>>>>0,1,index,input 
There are two forms of a parameter, which can be a string or a regular object. Returns a query to the string itself, or null if there is no string that specifies the query. If there is no global match in the join regular expression, returns an array of matched strings, and a subquery to the string that returns the index value of a query. And the string object being queried. Normalize:repeat:
var str= "Lili"; Str.repeat (2); >>>>>> "Lililili";
The parameter is the number of copies and an error occurs when the parameter is less than zero; Replace:
var str= "Hello world!" ; Str.replace ("L", ' O '); >>>>>> "Heolo world!" ; Str.replace (/l/g, "O"); >>>>>> "Heooo Worod"; Str.replace (/l/g,function() {     return "O";}) >>>>>> "Heooo Worod";
Replace accepts two parameters, and the second parameter, if not selected, replaces the target string with Undefind. The first argument can be a string, or it can be a regular object. The second argument can be a string, or it can be a function with a return value. Search
var str= "123456789.abcde"; Console.log (Str.search (".")); // 0 because of the regular. Match \ n any character Console.log (Str.indexof (".")); // 9 matches a string only. Console.log (str.search ("\ \")); //  Console.log (str.indexof ("\ \")); // -1 matches \. So there is no console.log (Str.search (/\./));  // 9 regular match after. Character // -1  equals match '/\./' so there is no
Search is a mandatory regular match slice:
var str= "Hello World"; Str.slice (0); >>>>>> "Hello World"str.slice (0,-1); >>>>>> "Hello worl"str.slice (2,1); >>>>>> ""
String.prototype.slice (star,end); the two parameter end parameter is an optional parameter, and the truncated string does not include the subscript for the end parameter. The end argument can be a negative number, which means that it is intercepted from the string. But the start parameter returns an empty string after the end argument. Split
var str= "Hello World"; Str.split (""); >>>>>>["H", "E", "L", "L", "O", "", "w", "O", "R", "L", "D"]str.split (/\s+/,1); >>>>>>["Hello"]
String.prototype.split (); two parameters, the second parameter is an optional parameter. Indicates the length of the numeric value to return, the first argument can be a string or it can be a regular expression. Indicates that the string is split. Substring
var str= "Hello World"; str.substring (0,5); >>>>>> "Hello"; str.substring (0); >>>>>> "Hello World";
String.prototype.subString () accepts two parameters and the second is an optional parameter. If not, all strings will be truncated. Usage is the same as slice, except that the second argument cannot be a negative number. Substr
var str= "Hello World"; Str.sbustr (0,5); >>>>>> "Hello"str.substr (-1,5); >>>>>> "World"str.substr (0); >>>>>> "Hello World"
String.prototype.substr (index,length), can accept two parameters, the first is the starting point subscript, the second is the length. The first parameter can be a negative value. When the second argument is empty, it is truncated to the end of the string. StartsWith:
var str= "Hello World"; Str.startswith ("Hello"); >>>>>>true;
As with endswith usage, start with what. The return value is a Boolean value. toLowerCase: Turns the string into lowercase. Tolocalelowercase:touppercase: Turns the string into uppercase. Tolocaleuppercase:trim: Remove the leading and trailing spaces. TrimRight: Remove the right space. Trimleft: Remove the left space. Link:anchor:fontcolor:fontsize:big:blink:bold:fixed:italics:small:strike:sub: Changes the string to subscript. SUP: Turn the string into superscript

All the methods of String.prototype JavaScript

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.