需求:將字符串" hello " 轉換成 " he-llo "(在第2個字母后邊加上特殊字符 " - " )
var str = "hello"; var newStr = str.slice(0, 1) + "-" + str.slice(1); console.log(newStr)
分析:slice(start, end):用於提取字符串的片段
需求:將字符串" hello " 轉換成 " he-llo "(在第2個字母后邊加上特殊字符 " - " )
var str = "hello"; var newStr = str.slice(0, 1) + "-" + str.slice(1); console.log(newStr)
分析:slice(start, end):用於提取字符串的片段
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。