如何在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 : PHPBook author is : Amit
Book price is : 250
以上是 如何在JavaScript中访问对象数组的属性? 的全部内容, 来源链接: utcz.com/z/316484.html