JavaScript中的TypedArray.indexOf()函数
indexOf()TypedArray对象的函数接受一个值,并验证类型化数组是否包含指定的元素。如果是这样,则此函数返回找到指定元素的数组的索引,如果该元素多次出现,则此函数返回其中的第一个索引。如果数组不包含指定的元素,则该indexOf()函数返回-1。
语法
其语法如下
typedArray.indexOf(50)
示例
<html>
<head>
<title>JavaScript Array every Method</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([21, 19, 65, 21, 14, 66, 87, 55, 66, 97, 66 ]);
document.write("Contents of the typed array: "+int32View);
document.write("<br>");
var contains = int32View.indexOf(66);
document.write("Specified element occurred at the index: "+contains);
</script>
</body>
</html>输出结果
: Contents of the typed array: 21,19,65,21,14,66,87,55 Specified element occurred at the index: 5
示例
<html>
<head>
<title>JavaScript Array every Method</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([21, 19, 65, 21, 14, 66, 87, 55, 66, 97, 66 ]);
document.write("Contents of the typed array: "+int32View);
document.write("<br>");
var contains = int32View.indexOf(634);
document.write("Specified element occurred at the index: "+contains);
</script>
</body>
</html>输出结果
: Contents of the typed array: 21,19,65,21,14,66,87,55 Specified element occurred at the index: -1
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短