对象的整理1

静态对象: 不需要创建, 直接通过这个对象名字调用即可, (内置对象)
实例对象: 通过构造函数创建出来, 实例化的对象

Math.PI --->π
 Math.abs(值)----> 取绝对值
Math.ceil(值)   ---> 向上取整
Math.floor(值)   ---> 向下取整
Math.round(值)   ---> 四舍五入
Math.max(值1, 值2....) 取一堆数字的最大值
Math.min(值1, 值2....) 取一堆数字的最小值
Math.pow(值1, 值2) 次方
Math.sqrt(值1) 平方根
Math.random() 随机数  区间是 0-1

在这里插入图片描述

Dath:

//获取年份
var dt = new Date();
console.log(dt.getFullYear());
//获取月份 区间 0-11
console.log(dt.getMonth()+1);
//获取日份
console.log(dt.getDate());
//获取星期 周天是 0 区间是0-6
console.log(dt.getDay())
//获取时 分 秒
console.log(dt.getHours());
console.log(dt.getMinutes());
console.log(typeof dt.getSeconds());

console.log(typeof dt.getTime());//时间戳  毫秒值  number类型
console.log(dt.valueOf());//毫秒值

console.log(typeof dt.toTimeString());//当前的时分秒
console.log(typeof dt);

string:
//1. 把"考试"截取出来
// var str = “hhhhhhhhhhhhh我想考试哈哈哈哈”;
// //获取字符串索引的位置
// var index = str.indexOf(“考试”);
// console.log(index);
// //从指定的位置截取, 截取2个
// console.log(str.substr(index, 2));

//2.找到这个字符中所有 o  出现的位置
// var str1 = "heolo";
//开始找的位置
// var index = 0;
// //要找的字符
// var key = "o";
// while (( index = str1.indexOf(key, index)) != -1){
//     console.log("索引值:"+index);//输出o的位置
//     console.log("key的长度"+key.length)
//    //
//     index +=  key.length
// }

// for(var i = 0 ; i < str1.length; i++){
//     console.log(str1.indexOf("o", i), i);
// }

//3.找到这个字符串中每个字符出现了多少次

// var obj = {
//     "sex":"男"
// }
// obj["age"] = 18;
// console.log(obj);
// // if的判断是true, 则有这个属性
//  if(obj["name"]){
//     console.log("有这个属性")
//  }else{
//      obj["name"] = "小明";
//      console.log("没有这个属性")
//      console.log(obj)
//  }

猜你喜欢

转载自blog.csdn.net/weixin_44392027/article/details/86021337