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));
    

      

  • 相关阅读:
    【Element UI】el-tooltip组件(提示消息) 换行
    复合文件CFB的存储结构及格式解析
    luogu P3801 红色的幻想乡 |容斥+树状数组
    luogu P3602 Koishi Loves Segments |堆+离散化贪心
    luogu P2048 [NOI2010] 超级钢琴 |堆+RMQ
    钉钉机器人使用注意事项
    k8s-部署
    docker 总结
    Navicat15最新版本破解 亲测可用!!!(Navicat Premium 注册出现 No All Pattern Found! File Already Patched)
    继续开始web的学习
  • 原文地址:https://www.cnblogs.com/yqlog/p/5546175.html
Copyright © 2011-2022 走看看