Math对象 Math.PI ---->π Math.abs(值)---->取绝对值 console.log(Math.abs(-4.1)); Math.ceil(值)----->向上取整 console.log(Math.ceil(4.1)); Math.floor(值)----->向下取整 console.log(Math.floor(4.9)); Math.round()------>四舍五入 console.log(Math.round(4.5)); Math.max(值1,值2,...)------>取最大值 console.log(Math.max(10,1,5)); Math.min(值1,值2,...)------>取最小值 console.log(Math.min(10,1,5)); Math.pow()----->次方 console.log(Math.pow(2, 5));//2的5次方 Math.sqrt()------>开更 console.log(Math.sqrt(16)); Math.random()------>随机取整 console.log(Math.random()); //区间0到1 console.log(Math.floor( Math.random()*5));//取0-4的随机整数 console.log(parseInt( Math.random()*5));//取0-4的随机整数
Date对象 //获取年份 var dt = new Date(); console.log(dt.getFullYear()); //获取月份 区间0-11 console.log(dt.getMonth()+1); //获取日份 console.log(dt.getDate()); //获取星期几,周几,区间0-6,周天是0 console.log(dt.getDay()); //获取时 console.log(dt.getHours()); //获取分 console.log(dt.getMinutes()); //获取秒 console.log(dt.getSeconds()); //时间戳 毫秒值 从1970年1月1号0点开始计算 console.log(typeof getTime());//number console.log(dt.valueOf()); //当前的时间 console.log(dt.toTimeString());
Array对象(略)
string对象
.length 字符串的长度 .charAt(索引) 返回值是指定索引位置的字符串, 索引值超出了, 返回时空字符串 .concat(字符串1, 字符串2...) 返回的是拼接之后新的字符串, 用变量去调用 .indexOf(要找的字符串, 从某个位置开始即索引值) 返回的是这个字符串的索引值(找到的第一个), 找不到则返回-1 .replace("原来的字符串", "新的字符串") 替换字符串的 .slice(开始的索引, 结束的索引) 截取0到5的字符串, 不包含索引为5的字符, 并返回(包前不包后) .split("要干掉的字符串", 干掉后留下的个数), 用于切割字符串 .substr(开始的位置, 个数) 返回的是截取后的一个新字符串 .substring(开始的索引, 结束的索引) 截取0到5的字符串, 不包含索引为5的字符, 并返回(包前不包后) .toLowerCase() 转小写 .toUpperCase() 转大写 .trim() 干掉字符串两端的空格