Find keys for the matched values - Javascript Object

Javascript examples for Object:Object Keys

Description

Find keys for the matched values

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 ava 2 s  . c o m
var data = {"100":"aaa","101":"RRR","102":"CCC","104":"Goa"};
function search(data, text){
   var items = {};
   for(var i in data){
     if(data.hasOwnProperty(i) && data[i].indexOf(text) !== -1){
       items[i] = data[i];
    }
  }
  return items;
}
console.log(search(data, '100'));
    }

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

Related Tutorials