Find duplicate value in JavaScript object - Javascript Object

Javascript examples for Object:Object Operation

Description

Find duplicate value in JavaScript object

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from   w  w w .  ja v a 2s.com*/
var answers = {'a': 3,'b': 2,'c': 3, 'd': 1};
var keys = Object.keys(answers);
var dupe = false;
for(var i=0;i<keys.length;i++){
 for(var j=i+1;j<keys.length;j++){
   if(answers[keys[i]] === answers[keys[j]]){
     dupe = true;
     break;
   }
 }
 if(dupe){ console.log("dupe value is there.."); break; }
}
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials