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

      

  • 相关阅读:
    jquery mobile左右滑动切换页面
    用phonegap和jquery-mobile写android应用
    javascript配置ckfinder的路径
    HTML5中表单验证的8种方法
    select标签中的选项分组
    c# 冒号:C#中两个冒号(::)的作用
    jquery validate
    【C#学习笔记】检测进程是否存在并关闭
    【C#学习笔记】载入图片并居中
    【C#学习笔记】鼠标控制
  • 原文地址:https://www.cnblogs.com/yqlog/p/5546175.html
Copyright © 2011-2022 走看看