内置对象
数学Math
Math.PI
Math.random()
-
[0,1)
- 取特定区间 Math.floor(Math.random()*50)+50
Math.abs
Math.max
Math.min
Math.pow(x,y)
- x的y次方
Math.sqrt()
- 开方
Math.floor
- 向下取整
Math.ceil
- 向上取整
Math.round
- 四舍五入
Math.sin/cos/tan/asin/acos/atan
日期Date
获取系统日期
- new Date()
设定一个日期
- new Date(“2022-08-31 12:12:12”)
get
-
getDay()
- 周几
-
getFullYear()
- 年份
-
getMonth()
-
月份
- 从0开始
-
-
getDate()
- 日期
-
getHours()
- 小时
-
getMinutes()
- 分钟
-
getSeconds()
- 秒钟
-
getTime()
-
时间戳
-
1970-1-1 0:0:0
- 毫秒值
-
-
set
转字符串
- toString()
- toLocalDateString()
- toLocalTimeString()
- toUTCTime()
字符串String
遍历
-
length
-
[0, length-1]
-
超出索引
- undefined
字符串不可变
- s[0]=“a” 无效
索引与字符
-
charAt(n)
- 求索引为n对应的字符
-
charCodeAt(n)
- 求索引为n对应的字符编码
-
indexOf(s)
-
求字符s的索引
- 从左向右
- -1代表没有找到
-
只找第一个
-
-
lastIndexOf(s)
-
只找第一个
-
求字符s的索引
- 从右向左
- -1代表没有找到
-
-
includes(s)
- 判断内部有没有子字符串
子字符串
-
slice(start,end)
-
start与end都可以省略
- 本身
-
end省略代表到最后
-
不包含end
-
-
substring(start,end)
- 从start到end(不包含)
-
substr(from,length)
-
从from开始取length个
-
from支持负值
- -1代表最后一个
-
开头结尾
-
startsWith(s)
- 以s开头
-
endsWith(s)
- 以s结尾
大小写
-
toLowerCase()
- 小写
-
toUpperCase()
- 大写
-
没有首字母大写
切割与替换
-
split(“”)
- 返回数组
-
replace(“old”, “new”)
-
替换
- 只有第一个
-