JavaScript 中对象是什么以及如何访问任意属性?**
访问对象的属性
如果没有对象,就没有 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
广告