js语法3 高级使用

/Math工具函数/
//1、π
consle.log(Math.PI)

//2、随机random()---> [0, 1)
consle.log(Math.random())

//3、向下取整,Math.floor()

//4、三角函数,反三角函数
Math.sin()
Math.asin()
Math.cos()
Math.acos()
Math.tan()
Math.atan()

//5、角度、弧度互换

//6、返回一个坐标对应的角度
Math.atan2() -------->(PI, PI]

//7、开根
Math.sqrt()

/数组的高级使用/
//1、array.length,获取数组的长度

//2、遍历一个数组
for(var key in array_num) {    //in用于,数组或表
    console.log(key + ":-->" + array_num[key];
}

//3、数组末尾加入一个元素push
array_num.push();

//4、查找对象,在数组中对应的索引indexOf
array_num.indexOf();

//5、删除数组的某个元素splice(索引, 删除个数)

//6、数组的排序,快速排序
//sort函数,要自己定义一个比较函数
array_num.sort(function(lhs, rhs) {
    if (lhs < rhs) {return -1;} //-1,lhs排rhs左边,升序格式
    else if(lhs > rhs) {return 1;} //1, 排右边
    else {return 0;} //相等,不改变
});

array_num.sort(function(a, b) {
    return a-b; //升序排列,b-a是降序
})

//7、随机打乱一个数列
array_num.sort(function(a, b) {
    if (Math.random() < 0.5) {
        return -1;
    }
    else {
        return 1;
    }
})
//调用array_num[0],则可以实现,从数组中随机抽出一个

/字符串高级使用/
//1、str.length

//2、str.indexOf()返回子串,首次出现的位置

//3、str.replace("aa", "bb");替换,重新生成字符串对象!!!

//4、toLowerCase变小写, toUpperCase变大写

/遍历/
//1、遍历一个表,for(key in table)

//2、删除一个表,
delete array["aa"];

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值