If value is in multidimensional array - Javascript Array Operation

Javascript examples for Array Operation:Multi Dimensional Array

Description

If value is in multidimensional array

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  va2  s. c  o m
var friends = [{
    user: {
        username: 'Test'
    }
}, {
    user: {
        username: 'Blah'
    }
}]
var matches = friends.filter(function (friend) {
    return friend.user.username == 'Test'
});
if (matches.length > 0) {
    console.log(matches[0]);
} else {
    console.log('else');
}
    }

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

Related Tutorials