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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP