字串轉陣列
let str = 'string'
let arr = []
arr = str.split() // arr = ['string'] 直接轉為陣列[0]專案
arr = str.split('') // arr = ['s','t','r','i','n','g'] 直接以單個字元分隔成陣列對應下標項
str = 's-t-r-i-n-g'
arr = str.split('-') // arr = ['s','t','r','i','n','g'] 以'-'分隔字串 複製程式碼
陣列轉字串
let arr = [1,2,3,4,5]
let str = ''
str = arr.join('') // str = '1,2,3,4,5' // 預設以逗號隔開
str = arr.join('-') // str = '1-2-3-4-5' // 以'-'隔開 複製程式碼