十四、内置对象
Math: 数学对象
属性:Math.PI 圆周率
方法:
Math.floor() 向下取整
Math.ceil() 向上取整
Math.round() 四色五入
Math.max(x1,x2,...) 最大值
Math.min(x1,x2,...) 最小值
Math.abs() 绝对值
Math.sqrt() 平方根
Math.pow(x,y) x的y次方
Math.random() 0(包含)-1(不包含)的随机数
Math.floor(Math.random()*(m-n))+n n(包含)-m(不包含)的随机数
Date日期对象:var date=new Date()
console.log(date.getFullYear()); //2022年
console.log(date.getMonth()+1); //8月,国外0-11
console.log(date.getDate()); //1号
console.log(date.getDay()); //1,星期一
console.log(date.getHours()); //14点
console.log(date.getMinutes()); //42分钟
console.log(date.getSeconds()); //25秒
console.log(date.getMilliseconds());//毫秒
两个日期相减
var cha=new Date("2022-8-3 00:00:00")-new Date();
十五、计时器
计时器:var id=setInterval("函数",间隔时间)
清除计时器:clearInterval(id)
定时器:执行一次
var id=setTimeOut("函数",延迟时间)
十六、String
属性: length:长度 方法:
1、字符串开头结尾
boolean startswith() //以....开头
boolean endswith() //以......结尾
2、查找字符串
number indexof() //返回第一个下标,找不到返回-1
number lastIndexof() //返回最后一个下标
boolean includes() //是否包含
3、字符串截取
string substr(startIndex,lenght) //从某个下标开始截取length个字符
//从startIndex下标开始截取到endIndex(不包含)
string substring(startIndex,endIndex)
string slice(startIndex,endIndex) //可以是负值
4、根据下标获取字符
string charAt(index) //根据下标返回字符
number charCodeAt(index) //根据下标返回字符的unicode码
String.fromCharCode(101) //unicode码转化为对应的字符
5、转换大小写
toLowerCase() //转换为小写
toUpperCase() //转换为大写
6、其他
string concat() //返回拼接后的字符串
string trim() //去掉两边的空白