JavaScript 中陣列物件的屬性有哪些?
藉助 Array 物件,您可以將多個值儲存在同一變數中。它儲存大小固定的同類型元素序列集合。
以下是 Array 物件的屬性列表 −
序號 | 屬性和說明 |
1 | constructor 返回建立物件的陣列函式的引用。 |
2 | index 該屬性表示字串中匹配項所對應的基於零的索引。 |
3 | input 此屬性僅存在於由正則表示式匹配建立的陣列中。 |
4 | length 反映了陣列中的元素數量。 |
5 | prototype prototype 屬性允許您為物件新增屬性和方法。 |
示例
我們來看一個原型屬性的示例
<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
廣告