JavaScript Math对象,String对象

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
            //Math工对象具类  直接调用,不需创建对象
            //1.属性
                1.    .PI    //π
                2.    .SQRT1_2    //返回返回 2 的平方根的倒数(约等于 0.707)。
                3.    .SQRT2    //返回 2 的平方根(约等于 1.414)。
//                ...
            //2.方法
//            1.    .round()  //四舍五入取整
//            2.    .random() //随机生成(0-1)之间一个数
            //.随机生成[x-y]之间一个整数
//            Math.round(Math.random()*(y-x)+x);
            var a=Math.round(Math.random()*5+15);//随机生成一个10-15之间一个数
            console.log(a);
//            3.    .ceil() //向上取整
            console.log(Math.floor(1.6));//2
//            4.    .floor() //向下取整
            console.log(Math.ceil(1.6));//1
//            5.    .max(1,2,3,...) //
//                ...
//                https://www.w3cschool.cn/jsref/jsref-obj-math.html
    

       
       //1.String对象
            //var str=new String("Hello W")
            var str="Hello W"
            //2.属性
                1.str.length
                2.str[0]
            //3.方法
                1.    .charAt(0) //str[0]
                2.    .toUpperCase() //字符串转为大写的
                3.    .toLowerCase() //
                4.    .indexOf(a,b) //若写b,从b开始往后找字符串中是否含指定内容a首次出现的位置
                                    //有,返回其最小的下标
                                    //无,返回-1
                5.    .lastIndexOf() //类似4,从后往前找,返回a首次出现的位置,最大的下标
                6.    .split("")  //若写了,以其去拆分成为数组
                    ...            
//                https://www.w3cschool.cn/jsref/jsref-lastindexof.html
        </script>
        
    </body>
</html>

猜你喜欢

转载自www.cnblogs.com/wangdongwei/p/11247046.html