JavaScript 中的对象是什么?如何访问任何属性?**

javascriptobject oriented programmingprogramming

访问对象的属性

没有对象就没有 JavaScript。布尔值、数字、函数等都是对象。以下方法解释了如何访问对象的属性。

示例 1

<html>
<body>
<script>
   myObj = {"name":"Ramesh","age":30,"family":
           [{"mother":"Geetha","father":"Rao"}],"city":"Berlin"};
           var res = myObj.family[0].mother;
  document.write(res);
</script>
</body>
</html>

输出

Geetha

示例 2

<html>
<body>
<script>
   myObj = {"name":"Ramesh","age":30,"family":
           [{"mother":"Geetha","father":"Rao"}],"city":"Berlin"};
   var res = myObj.city;
   document.write(res);
</script>
</body>
</html>

输出

Berlin

相关文章