Get JSON property from fully qualified string - Javascript JSon

Javascript examples for JSon:JSon String

Description

Get JSON property from fully qualified string

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  . ja v  a  2s  .  c  om
var a = {
    "b": {
        "c": 1
    }
}
var n = "d.c".split(".");
var x = a;
for (var i = 0; i < n.length; i++) {
    x = x[n[i]];
    if (typeof(x) == "undefined") {
        break;
    }
}
console.log(x);
    }

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

Related Tutorials