JS基础--String\Math\Date\Symbol
时间:2020-12-13 20:30:08
收藏:0
阅读:24
嗨!我是前端小M~~
String--字符串
属性:str.length 字符串的长度只能获取不能设置
方法:
- str.charAt(index) //返回字符串item
- str.charCodeAt(index) //ASCII码
- str.indexOf(item) str.lastIndexOf(item)//返回元素下标 -1表示没有该元素
- str.trim() // 通过返回值,去除字符串前后的空格
- str.toUpperCase() //转大写
- str.toLowerCase() //转小写
- str.concat(‘A‘) //除了“+”以外的拼接方式
- str.slice(startIndex,endIndex)//截取
Math--数学
方法:
- Math.random()//随机数
- Math.PI //Π 3.1415926.......
- Math.max() //取最大值
- Math.min() //取最小值
- Math.ceil()//向上取整
- Math.floor()//向下取整
- Math.round()//四舍五入
Date--日期对象
方法:
let timeObj = new Date(); let year = timeObj.getFullYear(); //年 let month = timeObj.getMonth()+1; //月 let day = timeObj.getDate(); //日 let hourse = timeObj.getHours(); //时 let minutes = timeObj.getMinutes(); //分 let seconds = timeObj.getSeconds(); //秒 console.log(year); console.log(month); console.log(day); console.log(hourse); console.log(minutes); console.log(seconds); console.log(timeObj); //2020-11-10T09:27:19.420Z 时间戳
Symbol--简单数据类型
只支持[ ]访问法
let obj ={ name:‘zhangsan‘, age:18, } let name = Symbol("name"); obj[name]="lisi"; console.log(obj)// name:‘zhangsan‘,age:18,Symbol(name)]: ‘lisi‘
原文:https://www.cnblogs.com/trail0226/p/14129224.html
评论(0)