js2 字符串对象 数组 时间类

来源:互联网 发布:2017年网络语言 编辑:程序博客网 时间:2024/06/06 19:18

1 字符串对象

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <script>        s1="Hello World";        s2= new String("Hello world");        console.log(typeof s1);        console.log(typeof s2);        document.write(s1.substr(1,4));        document.write('<br/>');//        顾前不顾后        document.write(s1.substring(2,4));    </script></head><body></body></html>


2. 数组

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <script>        var arrname=[1,2,3];        var arrnamew= new Array([1,2,3]);//        数组的join方法        var arr=["11","22","hell"];        var sl=arr.join('--');        document.write(sl);        console.log(sl);    function Mysort(m,n) {        return m-n;    }    var arr1=[100,56,23,4];    document.write(arr1.sort(Mysort));    </script></head><body></body></html>

3  时间类   可以进行时间的拼接   月份需要自己判断


<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <script>        var t = new Data();        alert(t.toLocaleString());    </script></head><body></body></html>



原创粉丝点击