国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

javascript - js determines whether there are duplicate values ??in the value in the JSON object?
給我你的懷抱
給我你的懷抱 2017-06-12 09:32:44
0
4
1306

How to determine if the value of specDesc in the JSON object cannot be the same

給我你的懷抱
給我你的懷抱

reply all(4)
大家講道理
if([...new Set(specList.map(item=>item.specDesc))].length < specList.length){
    console.log('有重復(fù)')
}
阿神

You can first traverse and push the value of obj.specDesc into an array, and then write a function to determine whether there are duplicates in the array

洪濤
var obj={};
for(var i=0,l=specList.length;i<l;i++){
 if(obj[specDesc[i].specDesc]){
   console.log('已存在');
 }else{
   obj[specDesc[i].specDesc]=specDesc[i].specDesc;
   console.log('不存在');
 }
}
僅有的幸福

Can’t we just judge directly? a['spec'] == b['spec'], If you want to compare the values ??corresponding to all keys, you need to traverse all the keys of one of them and compare them to find out whether the corresponding values ??of the other keys are equal.

Since the questioner only sent a screenshot, it is difficult to study the meaning of the question. My understanding: Two objects a and b are not allowed to have a key-value pair that is the same

Then the solution is as follows:

var a = {age:1, spec:'hello'},
    b = {age:21, spec:'hello'};
    
function noRepeat(obj1,obj2){
    var res = false;
    for(var key in obj1){
        if(obj1[key]==obj2[key]){
            res = true;
            break;
        }
    }
    return res;
}

noRepeat(a, b); // true

This is similar to the truth. How can the subject of the question answer this question? If you have any additional questions, please add them~

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template