数组对象中相同属性值的个数
group(arr) { var obj = {}; if (Array.isArray(arr)) { for (var i = 0; i < arr.length; i) { var isNew = arr[i].isNew; if (isNew in obj) obj[isNew].push(arr[i]); else obj[isNew] = [arr[i]]; } } return obj; }, max(obj) { var ret = 0; if (obj && typeof obj === “object”) { for (var key in obj) { var length = obj[key].length; if (length > ret) ret = length; } } return ret; }, var data = [ { addr: “1”, isNew: false, }, { addr: “2”, isNew: false, } ] max(group(data) // 2
检测版本是vue3
import { h } from ‘vue’; const isVue3 = typeof h === ‘function’; console.log(isVue3)
检测数据对象中是否有空对象
let arr = [{},{name:‘1’}] const arr = this.bannerList.filter(item => item == null || item == ‘’ || JSON.stringify(item) == ‘{}’ ); console.log(arr.length > 0 ? ‘不通过’ : ‘通过’)
更多内容请见原文,原文转载自:http://www.mark-to-win.com/tutorial/50894.html