字符串反转.html
<script type="text/javascript">
//反转字符口串
//abcdefg
//转大写
//1.split() 把字符串切割成数组
//2.reverse() 反转数组
//3.join() 把数组链接成字符串
//4.toUpperCase() 字符串转大写
var str='abcdefg'
var res=str.split('')
var res2=res.reverse()
var res3=res2.join(' ')
var res4=res3.toUpperCase()
//console.log(res) //(7) ["a", "b", "c", "d", "e", "f", "g"]
//console.log(res2) //(7) ["g", "f", "e", "d", "c", "b", "a"]
console.log(res3) //g f e d c b a
console.log(res4) //G F E D C B A
//优化版
var str='asdfg'
var res=str.split('').reverse().join(' ').toUpperCase()
console.log(str) //asdfg
console.log(res) //G F D S A
</script>