1.Math.abs(x):返回一个数的绝对值,x必须是整数
2.Math.trunc(x):去除一个数的小数部分,返回整数部分,不会四舍五入
console.log(Math.trunc(5.1))//5
console.log(Math.trunc(5.8))//5
console.log(Math.trunc(-5.1))//5
console.log(Math.trunc(-5.8))//5
console.log(Math.trunc(0.12345))//0
console.log(Math.trunc(-0.12345))//-0
对于非数值,Math.trunc内部会使用Number方法价格年起转换为数值
对于空值和无法取整数的值,返回NaN
**3.Math.sign:**用于判断一个数到底是整数,负数,还是零
1.参数为正:返回+1
2.参数为负:返回-1
3.参数为0:返回0
4.参数为-0:返回-0
5.其他值返回NaN
**4.Math.cbrt:**计算一个数的立方根
5.Math.clz32:js整数使用32位二进制形式表示
Math.clz32返回一个数的32位无符号整数形式有多少个前导0
6.Array.from(将两类对象转换为数组)
1.类似数组的对象(任何有length属性的对象)
2.可遍历的对象
let myObj={
“0”:“a”,
“1”:“b”,(必须指定下标)
length:2(必须指定length)
}
Array.from方法还可以接受第二个参数,和map类似:
Array.from([1,2,3,4],x=>x+x)等价于
Array.from([1,2,3,4]).map(x=>x+x)
es6学习笔记
最新推荐文章于 2023-04-04 16:49:40 发布