<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JavaScript字符串对象</title>
</head>
<body>
<script type="text/javascript">
var s1="实例化字符串方式一";
var s2=new String("实例化字符串abc方式二");
document.write(s1+"<br/>");
document.write(s2+"<br/>");
document.write(s2+"的长度是:"+s2.length+"<br/>");
document.write(s2.indexOf("abc",0)+"<br/>");
document.write(s2.replace("abc", "java1234")+"<br/>");
var date=new Date();
document.write(date.getTime()+"<br/>");
document.write(date.getFullYear()+"<br/>");
document.write((date.getMonth()+1)+"<br/>");
document.write(date.getDate()+"<br/>");
var today=date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日";
document.write(today+"<br/>");
document.write(date.getHours()+"<br/>");
document.write(date.getMinutes()+"<br/>");
document.write(date.getSeconds()+"<br/>");
today=date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日 "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
document.write(today+"<br/>");
var day=date.getDay();
var week;
switch(day){
case 0:week="星期日";break;
case 1:week="星期一";break;
case 2:week="星期二";break;
case 3:week="星期三";break;
case 4:week="星期四";break;
case 5:week="星期五";break;
case 6:week="星期六";break;
}
document.write(week+"<br/>");
today=date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日 "+week+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
document.write(today+"<br/>");
var arr=new Array();
var arr2=new Array(3);
arr[0]="jack";
arr[1]="marry";
arr[2]="tom";
arr[3]="lucy";
arr[4]="june";
arr2[0]=2;
arr2[1]=1;
arr2[2]=5;
//数组遍历
for(var i=0;i<arr.length;i++){
document.write(arr[i]+"<br/>");
}
document.write("<hr/>");
var o;
for(o in arr2){
document.write(arr2[o]+"<br/>");
}
//数组元素排序
document.write("<hr/>");
document.write("sort()"+arr.sort()+"<br/>");
document.write("sort()"+arr2.sort()+"<br/>");
document.write("<hr/>");
//合成字符数组元素
document.write("join()"+arr.join()+"<br/>");
document.write("join()"+arr2.join(".")+"<br/>");
document.write("<hr/>");
//合并数组元素
document.write("concat()"+arr.concat(arr2)+"<br/>");
document.write("<hr/>");
//颠倒数组元素
document.write("reverse()"+arr.reverse()+"<br/>");
</script>
</body>
</html>