JavaScript 中陣列物件有哪些屬性?
陣列物件讓你能將多個值儲存到單一變數中。它儲存固定大小的相同型別元素的順序集合。
以下列出的是陣列物件的屬性 -
序號 | 屬性與描述 |
1 | 建構函式 返回建立一個物件的陣列函式的引用。 |
2 | 索引 該屬性表示字串中匹配的以零為基礎的索引。 |
3 | 輸入 此屬性僅存在於由正則表示式匹配建立的陣列中。 |
4 | 長度 反映陣列中的元素數量。 |
5 | 原型 原型屬性允許你向物件新增屬性和方法。 |
示例
讓我們看一個原型屬性的示例
<html> <head> <title>JavaScript Array Object</title> <script> function book(title, author){ this.title = title; this.author = author; } </script> </head> <body> <script> var myBook = new book("Java", "John"); book.prototype.price = null; myBook.price = 300; 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 : Java Book author is : John Book price is : 300
廣告