length()
let str = "HelloWorld" ;
console. log ( str. length) ;
charAt()
let str = "HelloWorld" ;
console. log ( str. charAt ( 5 ) ) ;
concat()
let str = "Hello" ;
let str2 = "World" ;
console. log ( str. concat ( str2) ) ;
indexOf()
返回指定字符串在原字符串中第一次出現的位置。 參數:要查找的字符串。
let str = "HelloWorld" ;
console. log ( str. indexOf ( "o" ) ) ;
replace()
替換字符串。 參數:要替換的字符串,替換后的字符串。
let str = "HelloWorld" ;
console. log ( str. replace ( "W" , "w" ) ) ;
slice()
let str = "HelloWorld" ;
console. log ( str. slice ( 0 , 5 ) ) ;
toLowerCase()
let str = "HelloWorld" ;
console. log ( str. toLowerCase ( ) ) ;
toUpperCase()
let str = "HelloWorld" ;
console. log ( str. toUpperCase ( ) ) ;
trim()
let str = " HelloWorld " ;
console. log ( str. trim ( ) ) ;
includes()
判斷字符串是否包含指定字符串。 參數:要判斷的字符串。
let str = "HelloWorld" ;
console. log ( str. includes ( "o" ) ) ;
startsWith()
判斷字符串是否以指定字符串開頭。 參數:要判斷的字符串。
let str = "HelloWorld" ;
console. log ( str. startsWith ( "H" ) ) ;