String interception, method, slice, substring, substr.

 

 STR = the let ' abcdef ' ;
 // 0 
STR = str.slice ( 0 ); // return the whole string abcdef 
STR = str.substring ( 0 ); // return the whole string abcdef 
STR = str.substr ( 0 ) ; // return the entire string abcdef
 // use a parameter 
STR = str.slice ( 2 ); // taken after all of the characters in the second CDEF 
STR = str.substring ( 2 ;) // all taken after the second character CDEF 
STR = str.substr ( 2 ); // taken after all of the characters in the second CDEF 

// use two parameters 
STR = str.slice ( 2, 4 ); // taken cd characters between the second through fourth 
STR = str.substring ( 2 , 4 ); // taken cd characters between the second through fourth 
str = str.substr ( 2 , 4 ); // taken from the 3rd onward cdef characters between the number 4 

// use two negative 
STR str.slice = ( . 1 , - . 3 ); // taken first to the second bc between four characters 
STR str.substring = ( . 1 , - . 3 ); // taken characters between the second to fourth converted to negative a # 0 
STR str.substr = ( . 1 , - . 3 ) ; // can not be negative, if negative force transmission, will be processed as 0 '' is converted to a negative number # 0 
the console.log (STR) 
0 ----------------

Guess you like

Origin www.cnblogs.com/yuanjili666/p/12038215.html