js 中Math、Date对象和字符串常用方法

内置对象Math
    常量,Math.PI,   Math.E,  Math.LN2,  Math.LN10,  Math.LOG2E,   Math.LOG10E,  Math.SQRT2(根号2)
    成员函数:绝对值   Math.abs(-10);返回10;
    四舍五入:Math.round(1,3);
    取整:向下取整Math.floor() ;  向上取整:Math.ceil();
    指数和对数 e:Math.exp();    Math.log();
    任意数的指数:Math.pow(2,3);  
    根号:Math.sqrt();

    求最大值最小值
    Math.max(1,2,3.....); 
    Math.min(1,2,3....)
    
    随机值0~1之间的 平均分布的小数   大于等于0.0小于1.0的随机数
    Math.random();
内置对象Date,表示日期和时间
    var d = new Date();
    console.log(d);
    
    定时器:setTimeout     setInterval
    setTimeout调用时只是把任务放置到队列中,然后返回,等待规定的时间到了,会再调用回调函数(异步)
    setInterval每隔一段时间运行一次
    
字符串的常用方法:
    string.length:  字符串的长度
    string.charAt(索引)
    String.fromCharCode(ASCII值,可以多个)
    string.concat(拼接字符串)
    string.indexOf(),查找字符串
    string.lastIndexOf(): 查找字符串,从后往前查
    string.replace 字符串替换
        例:var str = 'hello world';
        console.log(str.replace(/o/g,'aa');//把o全部替换为aa

    string.slice();  截取字符串,但是不影响原来的字符串
    string.split();   基于某种分隔用途的字符,把字符串切割成字符串数组
        var str = 'png| jpg | bmp';
        var strArray = str.split('|');

    string.substr(start, length)     截取字符串
    string.substring( start, end)   截取字符串

    string.toLowerCase()   转换为小写
    string.toUpperCaser()  转换为大写

    string.trim() .trimLeft   .trimRight  去掉两边的空格或者等价的

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值