JS逆转字符串
var str = "doogyrevsig"document.write("
第一种方法:
" + "");document.write("
逆转前:
" + str + "");document.write("
逆转后:
");document.write(str.charAt(10));document.write(str.charAt(9));document.write(str.charAt(8));document.write(str.charAt(7));document.write(str.charAt(6));document.write(str.charAt(5));document.write(str.charAt(4));document.write(str.charAt(3));document.write(str.charAt(2));document.write(str.charAt(1));document.write(str.charAt(0));var str = "doogyrevsig"document.write("第二种方法:
" + "");document.write("
逆转前:
" + str + "");document.write("
逆转后:
");var i=str.length; for ( i ; i >= 0 ; --i ) { document.write(str.charAt(i)); } var str = "doogyrevsig"document.write("第三种方法:
" + "");document.write("
逆转前:
" + str + "");document.write("
网友评论