1.string类型可以调用的方法有哪些? string方法有哪些?
字符方法:
1.charAt(index) 返回指定位置索引的字符
2.charCodeAt(index) 返回指定位置索引字符的unicode编码
操作方法
1.substring(start,end) 截取字符串 从start位置截取到end(不包含end)位置 参数不可以为负数
2.concat(str1,str2) 拼接字符串 返回拼接好的字符串
3.substr(start,length) 截取字符串 从start位置截取length个字符 start也可以是负数
4.slice(star,end) 截取字符串 从start位置截取到end(不包含)位置 参数可以是负数
位置方法
1.indexOf(查找字符,fromIndex(可选)) 从前往后查找字符串中字符 表示从index位置开始查找字符串
2.lastIndexOf(查找字符,fromIndex(可选))从后往前 查找字符串中字符 表示从index位置开始查找字符串
转为大小写
1.toLowerCase() 将字符串中所有字母转为小写
2.toUpperCase() 将字符串中所有字母转为大写
3.toLocaleLowerCase() 将字符串中所有字母转为小写
4.toLocaleUpperCase() 将字符串中所有字母转为大写
匹配正则方法
1.match() 单独配合字符串使用 匹配字符串中字符 返回一个数组
2.search() 匹配字符串中字符 匹配到了返回下标
3.split(‘-’) 将字符串转为数组
4.replace(‘l’,‘L’) 替换字符串中的某一个字符
2.Number()原型方法
1.toString()转为字符串
2.toLocaleString()转为字符串
3.toFixed(2) 转为字符串
4.valueOf() 返回数字本身
Number静态属性
MIN_VALUE
MAX_VALUE
3.Math对象 操作数学
Math.Pi Π 3.1415926
Math.E 2.678xxxxxx
方法
min() 返回一组数中的最小数
max() 返回一组数中的最大数
ceil() 向上取整 2.1 3
floor() 向下取整 2.9 2
round() 四舍五入
random() 获取0-1之间随机数 [0,1)
sqrt() 获取一个数的平方根
4.Date对象 处理日期的对象
var now = new Date();
//获取年份
now.getFullYear()
//获取月份 0-11 +1 1-12
now.getMonth()
//获取一月中第几天
now.getDate()
//获取周几 0-6 0周日
now.getDay()
//获取小时
now.getHours()
//获取分钟
now.getMinutes()
//获取秒
now.Seconds();
//转为时间戳 保存时间格式 时间戳 2023-6-30 13位时间戳1546431231454
now.getTime() now.valueOf()
5.momentjs 处理日期时间工具库
1.安装momentjs
nodejs npm install moment --save
2.引入momentjs
var moment = require('moment');
3.使用momentjs
moment(需要处理的时间).format('YYYY-MM-DD HH:mm:ss')
6.lodash工具库 对js中的一些数组 函数 对象方法进行了封装
1.安装lodash
nodejs npm install lodash --save
2.引入lodash
var _ = require('lodash');
1.cloneDeep 实现深拷贝
2.compact 返回真值数组元素组成新数组
3.uniq 对数组进行去重