非常教程

JavaScript参考手册

TypedArray

typedArray.indexOf

indexOf()方法返回在类型数组中可以找到给定元素的第一个索引,如果不存在,则返回-1。 方法具有与Array.prototype.indexOf()相同的算法。 TypedArray是这里的类型化数组类型之一。

语法

typedarray.indexOf(searchElement[, fromIndex = 0])

参数

searchElement需要在类型化数组中定位的元素fromIndex搜索的起始下标。如果下标大于等于类型化数组长度,则返回 -1,意思是类型化数组不会被搜索。如果提供的下标值是负数,则被当做距离类型化数组尾部的偏移。注:如果提供的下标是负数,类型化数组仍然从前到后搜索。如果计算出来的下标小于 0,则会搜索整个类型化数组。默认为 0(搜索整个类型化数组)。

返回值

数组中元素的第一个下标;没有找到则返回-1

描述

indexOf使用严格相等(由 === 或三等号运算符使用的相同方法)比较searchElement和类型化数组的元素。

示例

var uint8 = new Uint8Array([2, 5, 9]);
uint8.indexOf(2);     // 0
uint8.indexOf(7);     // -1
uint8.indexOf(9, 2);  // 2
uint8.indexOf(2, -1); // -1
uint8.indexOf(2, -3); // 0

规范

Specification

Status

Comment

ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'TypedArray.prototype.indexOf' in that specification.

Standard

Initial definition.

ECMAScript 2017 Draft (ECMA-262)The definition of 'TypedArray.prototype.indexOf' in that specification.

Draft

浏览器兼容性

Feature

Chrome

Edge

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

45

(Yes)

37 (37)

No support

32

No support

Feature

Android

Chrome for Android

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

No support

No support

37 (37)

No support

No support

No support

JavaScript

JavaScript 是一种高级编程语言,通过解释执行,是一门动态类型,面向对象(基于原型)的解释型语言。它已经由ECMA(欧洲电脑制造商协会)通过 ECMAScript 实现语言的标准化。它被世界上的绝大多数网站所使用,也被世界主流浏览器( Chrome、IE、FireFox、Safari、Opera )支持。JavaScript 是一门基于原型、函数先行的语言,是一门多范式的语言,它支持面向对象编程,命令式编程,以及函数式编程。它提供语法来操控文本、数组、日期以及正则表达式等,不支持 I/O,比如网络