Checking whether key and value exist in Javascript object - Javascript Object

Javascript examples for Object:Object Keys

Description

Checking whether key and value exist 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  ww  w.j  a va  2s  .c  o  m
function my(value, object) {
    return Object.keys(object).map(function (key) {
        return object[key];
    }).some(function (_value) { return _value === value; })
}
console.log(my('bar', {foo: 'bar'})) // true
console.log(my('baz', {foo: 'bar'})) // false
    }

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

Related Tutorials