字符串对象
<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));