Js数组转字符串,字符串转数组

数组转字符串

const arr=['h','e','l','l','o']

console.log("原数组:",arr)

const str=arr.join('')

console.log("转成的字符串:",str),

效果图:

字符串转数组

const str="hello"

console.log("原字符串:",str)

const arr=str.split('')

console.log("转成的数组:",arr)

字符串的切割

原字符串为hello,word 想截取word,

const str="hello,word"

console.log("原字符串:",str)

const arr=str.split(',')

console.log("转成的数组:",arr)

arr[1]就是想要的word

 

 

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------如遇到问题:+WX:WAZJ-0508,及时联系---------------------------------------------------------------------------------------------------------------------------------------------------

你可能感兴趣的:(Js)