Match values of Array with JSON - Javascript JSon

Javascript examples for JSon:JSon Object

Description

Match values of Array with JSON

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  ww .j  a  va 2  s.  c o m*/
var arr = Arr = ["a", "b", "c"];
var json = '{"my":{"cat":[{"val":"d"},{"val": "c"}]}}'

var obj = JSON.parse(json);

var cate = obj.my.cat
for (var i = 0; i < Arr.length; i++) {
    for (var j = 0; j < cate.length; j++) {
        if (Arr[i] == cate[j].val) {
            console.log(cate[j].val)
        }
    }
}
    }

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

Related Tutorials