zoukankan      html  css  js  c++  java
  • JS内置对象

    字符串对象

    <script>
         //字符串对象
           var str = "Hello worldlsgjlsjg";
           document.write('string.length='+str.length);
         //查找索引
           document.write("<br/>indexof 'wor'",+str.indexOf('wor'));
        //字符串匹配
           document.write("<br/>mathch world————》"+str.match('world'));
         //字符串替换
           document.write('<br/>replace--->'+str.replace("Hello","RIRIR"));
          //字符串转换为数组
          var strArray = str.split(' ');
          document.write('<br/>strArray[0]='+strArray[0]);
    </script>
    

    日期对象

    /*------日期对象------*/
          document.write('<br/>日期对象<br/>');
    //    获取当前日期
          var date = new Date();
          document.write('<br/>date:'+date);
    //    获取年份
          document.write("<br/>"+date.getFullYear())
          //获取当前时间戳
          document.write("<br/>时间戳:"+date.getTime());
          //创建自定义日期
          date.setFullYear(2016,1,1);
          document.write("<br/>自定义的时间:"+date);
    

     数组对象

      /*------数组对象------*/
    //     数组合并
           var a =["Hello","world"];
           var b = ["lin","iw"];
           var c =a.concat(b);
           document.write("<br/>数组合并:"+c);
           
    //     数组排序
           var arry = ["a","b","c","b","a","f","e"];
           var numArray = [21,4,1,5,25,9,38,4];
           //升降序
           function compareFunc(a,b){
           	return b-a;
           }
           document.write("<br/>数组排序"+arry.sort());
           document.write("<br/>数组升降序排序"+numArray.sort(compareFunc));
    //     数组追加值
           arry.push("zhuijia");
           document.write("<br/>数组追加"+arry);
    
    //     数组翻转
           document.write("<br/>数组翻转"+numArray.reverse());
    

    Math对象

      /*------Math对象------*/
         document.write("<br/>四舍五入:"+Math.round(2.5));
    //   随机数
         document.write("<br/>随机数:"+parseInt(Math.random()*10));
       //求最大值
         document.write("<br/>求最大值:"+Math.max(1,2.4325,525,53,5))
        //求绝对值
         document.write("<br/>求绝对值:"+Math.abs(-10));
    

      

  • 相关阅读:
    Codeforces 1291 Round #616 (Div. 2) B
    总结
    刷新DNS解析缓存+追踪+域名解析命令
    数学--数论--Hdu 5793 A Boring Question (打表+逆元)
    Lucene.net(4.8.0) 学习问题记录六:Lucene 的索引系统和搜索过程分析
    LeetCode 117 Populating Next Right Pointers in Each Node II
    LeetCode 116 Populating Next Right Pointers in Each Node
    test test
    LeetCode 115 Distinct Subsequences
    LeetCode 114. Flatten Binary Tree to Linked List
  • 原文地址:https://www.cnblogs.com/yqlog/p/5546175.html
Copyright © 2011-2022 走看看