JavaScript 中数组对象的属性是什么?
javascriptweb developmentfront end technology
数组对象允许您在单个变量中存储多个值。它存储相同类型的元素的固定大小顺序集合。
以下是数组对象的属性列表 −
Sr.No | 属性 &说明 |
1 | constructor 返回对创建该对象的数组函数的引用。 |
2 | index 该属性表示字符串中匹配项的从零开始的索引。 |
3 | input 此属性仅存在于通过正则表达式创建的数组中匹配。 |
4 | length 反映数组中元素的数量。 |
5 | prototype 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