-
翻翻过去那场雪
题主都问ES6了,怎么没人回答一下咩const data = { "bqw":"123", "bfr": "1234", "asq": "1235", "ase":"1236", "bd": "1237", "bua": "123", "bgg": "1238", "bug": "1239", };// ES7Object.values(data).length !== new Set(Object.values(data)).size && console.log('重复')// ES6const values = Object.keys(data).map(e => data[e])values.length !== new Set(values).size && console.log('重复')// 自行替换console.log 为alert
-
HUWWW
写个方法,把data的value作为key值重新建个对象;function run(obj){ let md={}; for(k in obj){ md[obj[k]]? md[obj[k]]++: md[obj[k]]=1 } return md;}//输出value出现的次数run(data)//123: 2, 1234: 1, 1235: 1, 1236: 1, 1237: 1, 1238: 1, 1239: 1
-
波斯汪
let check = (data) => {let arr = []for (let k in data) { if (arr.indexOf(data[k]) === -1) { arr.push(data[k]) } else { return true }} } let data = { "bqw": "123", "bfr": "1234", "asq": "1235", "ase": "1236", "bd": "1237", "bua": "123", "bgg": "1238", "bug": "1239"}if (check(data)) {alert('重复')}// true大概就是一个数组临时保存object的值,indexof来判断下一值在数组中是否存在,存在返回true