日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

使用filter過濾器計算數組中符合條件的長度

作者:Zan^Z 更新時間: 2022-02-13 編程語言

數組為:

son_window: [{ selectedCheckbox: false},
            { selectedCheckbox: false},
            { selectedCheckbox: true},
            { selectedCheckbox: true},
            { selectedCheckbox: false}],

使用for循環計算如下

    var sum;
	for (var i = 0; i < son_window.length;i++){
        if (son_window[i].selectedCheckbox == true) {                             
               sum = sum + 1;
        } 
    }

還有filter過濾器如下:(一行代碼搞定)


var sum = son_window.filter(function (x, y) { return x.selectedCheckbox == true }).length;

原文鏈接:https://blog.csdn.net/Zan_Z/article/details/106810222

欄目分類
最近更新