免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
JavaScript連載22-數(shù)組中其他方法以及Math對(duì)象

一、數(shù)組中其余的常用方法

  • 包括map,filter,every,some方法,我們分別進(jìn)行舉例
    //map定義一個(gè)函數(shù)用來(lái)遍歷原來(lái)老的數(shù)組
    var arr = [10,20,5,1000,50];
    var newArr = arr.map(function(value, index, array){
        return value>10 && value*2 ;//value大于10的時(shí)候才會(huì)乘2
    });
    console.log(newArr);
    //filter()定義一會(huì)判斷條件然后把滿足要求的數(shù)組選出來(lái)
    var arr2 = [1,2,3,4,5,6,7,8];
    var newArr2 = arr2.filter(function (value,index,array) {
        return index%2 == 0 || value >5;
    });
    console.log(newArr2);
    //every()定義一個(gè)判斷條件,然后返回是不是每個(gè)值都都滿足判斷條件
    var arr3 = [11,2,3,4,15];
    var newArr3 = arr3.every(function (value, index) {
        return value>1;
    });
    console.log(newArr3);
    //some()定義一個(gè)判斷條件,然后返回是不是存在一個(gè)值都都滿足判斷條件
    var arr4 = [11,2,3,4,15];
    var newArr4 = arr4.some(function (value, index) {
       return value>100;
    });
    console.log(newArr4);

 

 

運(yùn)行結(jié)果

二、內(nèi)置對(duì)象-Math

  • 在Math包中有許多我們常用的函數(shù),下面我們舉一些常用的例子,重點(diǎn)在隨機(jī)數(shù)生成區(qū)間
    //1.圓周率
    console.log(Math.PI);
    //2.向上取整數(shù)ceil,向下取整數(shù)floor
    console.log(Math.ceil(Math.PI));
    console.log(Math.floor(Math.PI));
    //3.取整數(shù),四舍五入
    console.log(Math.round(3.4));
    console.log(Math.round(3.5));
    console.log("=======================");
    //4.取絕對(duì)值
    console.log(Math.abs(-3));
    console.log(Math.abs(4));
    //5.求最大值和最小值
    console.log(Math.min(8,245,52,58,2,45,45));
    console.log(Math.max(4,5,8,7,6,4));
    console.log("=======================")
    //6.生成隨機(jī)數(shù)
    console.log(Math.random())//0-1之間的隨機(jī)數(shù)
    console.log(Math.random()*10)//0-10之間的隨機(jī)數(shù)
    //假如我們想要3-8之間的隨機(jī)數(shù),我們應(yīng)該怎么辦
    //有一個(gè)公式  Math.random() * (y - x) + x
    //比如我們想要5-9之間的隨機(jī)數(shù),那么就是
    console.log(Math.random() * (9 - 5) + 5);
    //7.正余弦
    console.log(Math.sin(Math.PI / 2));
    console.log(Math.cos(Math.PI / 2));//得到的數(shù)值已經(jīng)接近0了
    //8.求指數(shù)冪pow(),求平方根
    console.log(Math.pow(5, 4));
    console.log(Math.sqrt(4));

 

 

運(yùn)行結(jié)果:

  • 靜態(tài)成員和實(shí)例成員
//靜態(tài)成員
var LKTool = {
  height:function(){
  }
};
console.log(LKTool.height);
//實(shí)例成員
function Dog(name,sex){
  this.name = name;
  this.sex = sex;
}

var dog = new Dog("xiaoming","male");
console.log(dog.name);

 

 

運(yùn)行結(jié)果

三、源碼:

    • D22_1_AddedMethod.html
    • D22_2_MathObject.html
    • 地址:https://github.com/ruigege66/JavaScript/blob/master/D22_1_AddedMethod.html
      https://github.com/ruigege66/JavaScript/blob/master/D22_2_MathObject.html
    • 博客園:https://www.cnblogs.com/ruigege0000/
    • 歡迎關(guān)注微信公眾號(hào):傅里葉變換,個(gè)人賬號(hào),僅用于技術(shù)交流,后臺(tái)回復(fù)“禮包”獲取Java大數(shù)據(jù)學(xué)習(xí)視頻禮包
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
JavaScript 基礎(chǔ)四
前端js數(shù)組元素的篩選,修改,新增屬性小技巧一
JavaScript基礎(chǔ)案例篇(題目附代碼)
JS中數(shù)組實(shí)現(xiàn)(倒序遍歷數(shù)組,數(shù)組連接字符串)
5個(gè)數(shù)組Array方法: indexOf、filter、forEach、map、reduce使用實(shí)例
一個(gè)不確定內(nèi)容的數(shù)組,統(tǒng)計(jì)每個(gè)元素出現(xiàn)的次數(shù)的方法
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服