如何在JavaScript中访问对象数组的属性?
要访问对象数组的属性,可以尝试运行以下代码-
示例
<html>
<head>
<title>User-defined objects</title>
<script>
function book(title, author){
this.title = title;
this.author = author;
}
</script>
</head>
<body>
<script>
var myBook = new book("PHP", "Amit");
book.prototype.price = null;
myBook.price = 250;
document.write("Book title is : " + myBook.title + "<br>");
document.write("Book author is : " + myBook.author + "<br>");
document.write("Book price is : " + myBook.price + "<br>");
</script>
</body>
</html>输出结果
Book title is : PHP Book author is : Amit Book price is : 250
热门推荐
10 牙医生日祝福语简短
11 对别人新年祝福语简短
12 新年祝福语大全简短老师
13 宝宝100日简短祝福语
14 鼠年新年贺卡祝福语简短
15 最美的留言祝福语简短
16 祝福语勤奋大全简短英语
17 18岁的祝福语简短
18 同学分开祝福语简短