JavaScript中的TypedArray.entries()函数
该entries()TypedArray的函数返回相应的TypedArray对象,并使用此的迭代器,你可以检索它的键值对。它返回数组的索引以及该特定索引中的元素的位置。
语法
它的语法如下
typedArray.entries()
示例
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([21, 64, 89, 65, 33, 66, 87, 55]);
document.write("Contents of the typed array: "+int32View);
document.write("<br>");
var it = int32View.entries();
for(i=0; i<int32View.length; i++) {
document.write(it.next().value);
document.write("<br>");
}
</script>
</body>
</html>输出结果
Contents of the typed array: 21,64,89,65,33,66,87,55 0,21 1,64 2,89 3,65 4,33 5,66 6,87 7,55
示例
如果在迭代器指向数组末尾时尝试访问数组的下一个元素,则结果将不确定。
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([21, 64, 89, 65, 33, 66, 87, 55]);
document.write("Contents of the typed array: "+int32View);
document.write("<br>");
var it = int32View.entries();
for(i=0; i<int32View.length; i++) {
document.write(it.next().value);
document.write("<br>");
}
document.write(it.next().value);
</script>
</body>
</html>输出结果
Contents of the typed array: 21,64,89,65,33,66,87,55 0,21 1,64 2,89 3,65 4,33 5,66 6,87 7,55 undefined
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短