js字串的操作

2021-09-12 06:46:13 字數 489 閱讀 6447

一 字串的使用

1 另個數之間用加號表示運算

2 剩下的表示字串的拼接

var str = 'hello,world'

str.charat(0) //'h':第乙個字元

str.charat(str.length-1) //'d':最後乙個字元

str.substr(2,4) // 'll0,'

console.log(str.substr(2,4))

str.substring(1,4) //'ell':第二到四個字元

str.slice(1,4) //同上

str.slice(-3) //最後三個字元

str.indexof('l') //2: 字元1首次出現的位置

str.lastindexof('l') //10 字串l最後出現的位置

str.replace('h','h') //"hello,world"

js字串操作

返回指定位置的字元 var str hello world document.write the first character is str.charat 0 document.write the second character is str.charat 1 document.write th...

JS字串操作

字串中常用的方法 let str werwafdgaewfgrjyyu str.length 字串長度 str 0 第乙個字元 str str.length 1 最後乙個字元 str 100000 undefined 不存在這個索引 for let i 0 i charat charcodeat s...

js 操作字串,

字串補全 12345 padstart 7,0 0012345 字串不足7位,在頭部補充不足長度的目標字串 12345 padend 7,0 1234500 在尾部進行字串補全 字串轉換成陣列 array.of 3,4,5 3,4,5 字串重複輸出 var str 1,2,3 重複輸出5遍 cons...