Determine whether the values of different key of the object data are duplicated, and if there is an alert "repeat", how to operate with ES6. Or JQUERY can.

data = {
      "bqw":"123",
      "bfr": "1234",
      "asq": "1235",
      "ase":"1236",
      "bd": "1237",
      "bua": "123",
      "bgg": "1238",
      "bug": "1239",
    };

/ / determine whether the values of different key of the object data are duplicated, and if there is an alert "repeat"

Mar.05,2021

the subject has asked ES6, why is there no answer?

const data = {
      "bqw":"123",
      "bfr": "1234",
      "asq": "1235",
      "ase":"1236",
      "bd": "1237",
      "bua": "123",
      "bgg": "1238",
      "bug": "1239",
    };


// ES7
Object.values(data).length !== new Set(Object.values(data)).size && console.log('')

// ES6
const values = Object.keys(data).map(e => data[e])
values.length !== new Set(values).size && console.log('')
// console.log alert

write a method to recreate an object with the value of data as the key value;

function run(obj){
    let md={};
    for(k in obj){
        md[obj[k]]? md[obj[k]]PP: 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
is probably an array that temporarily stores the value of object. Indexof determines whether the next value exists in the array, and returns true

if it exists.
Menu