<script>
var str="abcdefgh"
//1、将字符串转成数组形式:split()
var arr=str.split("")
console.log(arr)//["a", "b", "c", "d", "e", "f", "g", "h"]
//2、将数组转成字符串形式:join()
var strings=arr.join("")//
console.log(strings)//abcdefgh
//2、将数组元素反转:reverse()函数只能反转数组
var rever=arr.reverse()
console.log(rever.join(""))//hgfedcba
</script>
js字符串转换成数组、数组转换字符串、数组倒序转为字符串
最新推荐文章于 2024-08-09 15:07:14 发布