String对象
<script language="javascript">
var s1 = "hello world";
var s2 = new String("hello world");
alert(s1.charAt(4));
alert(s1.indexOf("r"));
alert(s1.lastIndexOf("r"));
alert(s1.indexOf("r"));
var s3 = "a,b,c,d";
var s4 = s3.split(",");
for()var i=0;i<s4.length;i++{
alert(s4[i]);
}
</script>
Date对象
<script language="javascript">
var d = new Date();
alert(d.getYear());
alert(d.getMonth());
alert(d.getDate());
alert(d.getTime());
</script>
Math对象
<script language="javascript">
alert(Math.random()); //随机数
alert(Math.round(-10.6)); //据目标数最近的整数
alert(Math.round(Math.random()*10));//据随机数最近的整数
</script>
<script language="javascript">
var testArray1 = new Array(10);
for(var i=0;i<testArra1.length;i++){
testArray[i]=i;
}
for(var i=0;i<testArray1.length;i++){
document.write(testArray1[i]);
}
document.write("<p>");
testArray1.reverse(); //降序
for(var i=0;i<testArray.length;i++){
document.write(testArray1[i]);
}
testArray1.sort(); //升序
for(var i=0;i<testArray.length;i++){
document.write(testArray1[i]);
}
</script>
数组:
<script language="javascript">
var testArray = ['1','2',a'','b'];
testArray.sort(); //将数组升序排列
testArray.reverse(); //颠倒数组中的元素
</script>
<script language="javascript">
var s1 = "hello world";
var s2 = new String("hello world");
alert(s1.charAt(4));
alert(s1.indexOf("r"));
alert(s1.lastIndexOf("r"));
alert(s1.indexOf("r"));
var s3 = "a,b,c,d";
var s4 = s3.split(",");
for()var i=0;i<s4.length;i++{
alert(s4[i]);
}
</script>
Date对象
<script language="javascript">
var d = new Date();
alert(d.getYear());
alert(d.getMonth());
alert(d.getDate());
alert(d.getTime());
</script>
Math对象
<script language="javascript">
alert(Math.random()); //随机数
alert(Math.round(-10.6)); //据目标数最近的整数
alert(Math.round(Math.random()*10));//据随机数最近的整数
</script>
<script language="javascript">
var testArray1 = new Array(10);
for(var i=0;i<testArra1.length;i++){
testArray[i]=i;
}
for(var i=0;i<testArray1.length;i++){
document.write(testArray1[i]);
}
document.write("<p>");
testArray1.reverse(); //降序
for(var i=0;i<testArray.length;i++){
document.write(testArray1[i]);
}
testArray1.sort(); //升序
for(var i=0;i<testArray.length;i++){
document.write(testArray1[i]);
}
</script>
数组:
<script language="javascript">
var testArray = ['1','2',a'','b'];
testArray.sort(); //将数组升序排列
testArray.reverse(); //颠倒数组中的元素
</script>