数组和字符串

数组和字符串转换

字符串转数组

const Str = "1,2,3,3,"
consr Arr = Str.split(',')//","指的是字符串的分隔点
console.log(Arr);//Arr=[1,2,3,3]

数组转字符串

const Arr = [1,2,3,4]
consr Str = Str.join(',')//","指的是数组的分隔点
console.log(Str);//Str="1,2,3,4"

数组截取

const Arr = [a,b,c,d,e,f,g]
console.log(Arr.slice(1,4)) // Arr[b,c,d,e] 取第1个到第4个 (从0开始数)

字符串截取

const Str = "1234hhhh"
console.log(Str.substring(0, 2))//Str="123" 取第0个到第2个 (从0开始数)

 


 

 

posted @ 2022-11-17 10:00  入世凡尘  阅读(33)  评论(0)    收藏  举报