js 内置对象常用方法

    技术2022-07-11  83

    number对象

    四舍五入的的函数

    Math.round(num)

    向下取整

    Math.floor(num)

    向上取整

    Math.ceil(num)

    随机数

    Math.random()

    这是x的y次幂 > Math.pow(x,y) num的平方根

    Math.sqrt(num)

    绝对值

    math.abs(num)

    string 函数

    分割函数,返回一个数组 str.split(str);

    获取字符串出现第一次的char 的下标 str.indexOf(char);

    获取字符串出现最后一次的char 下标 str.lastIndexOf()

    切割字符串,不支持负数,返回新字符串 str.substr(start,end)

    切割字符串,支持负数,返回新字符串 str.slice(start,end)

    这个和slice()一样 str.substring(start,end)

    时间函数

    年 > timeObj.getFullYear() 月 > timeObj.getMonth() 日 > timeObj.getDate() 星期 > timeObj.getDay() 小时 > timeObj.getHours() 分钟 > timeObj.getMinutes() 秒 > timeObj.getSeconds()

    数组函数

    逗号分割 arr.toString()

    删除第一个元素 arr.shift()

    增加一个元素 arr.push()

    删除数组最后一个元素 arr.pop()

    在开头增加一个元素 arr.unshift()

    直接操作数组,从index开始删除num个元素,增加后面的元素到数组中,返回删除的元素, arr.splice(index,num,“yuansu1”,“yuansu1”,“yuansu1”)

    Processed: 0.011, SQL: 9