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
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~
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
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:
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~