Find an entire object in array of objects - Javascript Array Operation

Javascript examples for Array Operation:Array of Object

Description

Find an entire object in array of objects

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  .j a va 2s.  co  m
var array1 = [{
    h: 148,
    rid: 16,
    sid: 2
  }, {
    h: 8,
    rid: 18,
    sid: 9
  }
];
var array2 = {
  h: 1,
  rid: 16,
  sid: 2
};

var dat1= JSON.stringify(array2);

array1.forEach(function(item){
 if(JSON.stringify(item)===dat1){
    console.log(dat1)
 }else{
    console.log('Not match')
 }
});
    }

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

Related Tutorials