JS string method (new method comprises ES6)

charAt (): Returns the character specified location.

was string value = 'Hello World' ; 
alert (stringValue.charAt ( 1)); // 'e'

 

the charCodeAt (): returns the Unicode encoded character from the predetermined position.

var stringValue = 'hello world';
alert(stringValue.charCodeAt(1)); // '101'

 

fromCharCode (): The Unicode character encoding into.

var n = String.fromCharCode(65); // A

 


 

the concat (): connecting two or more strings and returns the new string.

var str1 = "Hello ";
var str2 = "world!";
var n = str1.concat(str2); // Hello world!

 

REPEAT (): copy the string specified number of times, and returns.

var str = "Runoob";
console.log(str.repeat(2));

 

Split (searchValue / regexp, limit): the string is divided into an array of strings.

var str="How are you doing today?";
var n=str.split(" ",3); // ["How", "are", "you"]

 

TRIM (): removal of both sides of the blank string.

var str = "       Runoob        ";
alert(str.trim()); // Runoob

 


 

Slice (Start, End): Select the part of the string, did not return.

var str="Hello world!";
var n=str.slice(1,5); // ello

 

substr (Start, length): selecting a specified number of the string, and return.

var str="Hello world!";
var n=str.substr(2,3) // llo

 

substring (): Select the part of the string, did not return.

var str="Hello world!";
var n=str.slice(1,5); // ello

 


 

indexOf (searchValue, Start): Returns the position of the first occurrence of the specified string in a string.

var str="Hello world, welcome to the universe.";
var n=str.indexOf("welcome"); // 13

 

lastIndexOf (): returns the position of the last occurrence of the specified string in the string.

var str="I am from runoob,welcome to runoob site.";
var n=str.lastIndexOf("runoob"); // 28

 

Includes (): Find string contains the specified string.

var str = "Hello world, welcome to the Runoob。";
var n = str.includes("world"); // true

 

startsWith ( searchValue ,  Start): see if the string begins with the specified string.

var str = "Hello world, welcome to the Runoob.";
var n = str.startsWith("world", 6); // true

 


 

match (regexp): retrieving a value specified in string to find the one or more regular expression matching.

var str="The rain in SPAIN stays mainly in the plain"; 
var n=str.match(/ain/g); // ["ain", "ain", "ain"]

 

Replace (searchValue / regexp, newValue): matching the search string in the string, and replace.

var str="Visit Microsoft! Visit Microsoft!";
var n=str.replace("Microsoft","Runoob"); // Visit Runoob!Visit Microsoft!

 

Search (searchValue / regexp): return position and regular expression matching string.

var str="Visit Runoob!"; 
var n=str.search("Runoob"); // 6

 


 

the toLowerCase (): converts a string to lowercase.

var str="Runoob";
console.log(str.toLowerCase()); // runoob

 

the toUpperCase (): converts a string to upper case.

var str="Runoob";
console.log(str.toUpperCase()); // RUNOOB

 

toLocaleLowerCase (): The local host language environment string to lowercase.

var str="Runoob";
console.log(str.toLocaleLowerCase()); // runoob

 

toLocaleUpperCase (): according to the local host's locale string converted to uppercase.

var str="Runoob";
console.log(str.toLocaleUpperCase()); // RUNOOB

 


 

valueOf (): returns a string of the original value.

var str="Hello world!";
console.log(str.valueOf()); // Hello world!

 

toString (): returns a string.

var str = "Runoob";
var res = str.toString(); // Runoob

 


 

charAt

charCodeAt

fromCharCode

concat

repeat

split

trim

slice

substr

substring

indexOf 

lastIndexOf

includes

startsWith

match

replace

search 

toLowerCase

toUpperCase

toLocaleLowerCase

toLocalUpperCase

Guess you like

Origin www.cnblogs.com/linxian95/p/10480949.html