数组转换为字符串
使用 arr.join()
let arr=[1, 2, 3, 4, 5, 6, 7, 8, 9]
arr.join() // "1,2,3,4,5,6,7,8,9"
字符串转为数组
使用 str.split(’’)
let str='123456789'
str.split() // ["1", "2", "3", "4", "5", "6", "6", "7"]
数组截取
使用 arr.splice(0,1) / 第一个参数起始位置 第二个参数 需要截取的位数 原数组会改变
let arr=[1, 2, 3, 4, 5, 6, 7, 8, 9] // 需要截取7,8
arr.splice(6,2) // [1, 2, 3, 4, 5, 6, 9]
字符串截取
使用 str.substring(0,1) 第一个参数起始位置索引 第二个参数 需要截取的参数索引 原字符串会改变
let str='123456789' //需要截取2,3
str.substring(1,3)
来源:https://blog.csdn.net/bossxu_/article/details/102753042