百科狗-知识改变命运!
--

Int8Array - JavaScript TypedArray 对象

梵高1年前 (2023-11-21)阅读数 40#技术干货
文章标签数组

Int8Array

Int8Array类型数组表示二进制补码8位有符号整数的数组。内容初始化为0。一旦建立,你可以使用对象的方法引用数组中的元素,或使用标准数组索引语法(即,使用括号注释)。

语法

new Int8Array(length);
new Int8Array(typedArray);
new Int8Array(object);
new Int8Array(buffer [, byteOffset [, length]]);

有关构造函数语法和参数的更多信息,请访问TypedArray.

属性

Int8Array.BYTES_PER_ELEMENT返回数组中每个元素的大小.在Int8Array中这个值为1.Int8Array.length此属性为固定值属性,值为3.查看Int8Array.prototype.length获得获取数组内元素个数方法。Int8Array.name返回构造器方法名称.在Int8Array类型中此值为"Int8Array"。Int8Array.prototypeTypedArray对象的构造原型。

方法

Int8Array.from()从类数组对象或迭代器生成int8Array数组对象.参照Array.from().Int8Array.of()以多个参数构造Int8Array对象,参照Array.of().

Int8Array原型方法

Int8Array - JavaScript TypedArray 对象

所有 Int8Array对象都继承自%TypedArray%.prototype.

属性

Int8Array.prototype.constructor这个方法会返回对象的构造原型.默认为Int8Array构造函数.Int8Array.prototype.buffer只读Returns the ArrayBuffer referenced by the Int8Array Fixed at construction time and thus read only.Int8Array.prototype.byteLength只读Returns the length(in bytes)of the Int8Array from the start of its ArrayBuffer. Fixed at construction time and thus read only.Int8Array.prototype.byteOffset只读Returns the offset(in bytes)of the Int8Array from the start of its ArrayBuffer. Fixed at construction time and thus read only.Int8Array.prototype.length只读Returns the number of elements hold in the Int8Array. Fixed at construction time and thus read only.

方法

Int8Array.prototype.copyWithin()Copies a sequence of array elements within the array. See also Array.prototype.copyWithin().Int8Array.prototype.entries()Returns a new Array Iterator object that contains the key/value pairs for each index in the array. See also Array.prototype.entries().Int8Array.prototype.every()Tests whether all elements in the array pass the test provided by a function. See also Array.prototype.every().Int8Array.prototype.fill()Fills all the elements of an array from a start index to an end index with a static value. See also Array.prototype.fill().Int8Array.prototype.filter()Creates a new array with all of the elements of this array for which the provided filtering function returns true. See also Array.prototype.filter().Int8Array.prototype.find()Returns the found value in the array, if an element in the array satisfies the provided testing function or undefined if not found. See also Array.prototype.find().Int8Array.prototype.findIndex()Returns the found index in the array, if an element in the array satisfies the provided testing function or -1 if not found. See also Array.prototype.findIndex().Int8Array.prototype.forEach()Calls a function for each element in the array. See also Array.prototype.forEach().Int8Array.prototype.includes()Determines whether a typed array includes a certain element, returning true or false as appropriate. See also Array.prototype.includes().Int8Array.prototype.indexOf()Returns the first(least)index of an element within the array equal to the specified value, or -1 if none is found. See also Array.prototype.indexOf().Int8Array.prototype.join()Joins all elements of an array into a string. See also Array.prototype.join().Int8Array.prototype.keys()Returns a new Array Iterator that contains the keys for each index in the array. See also Array.prototype.keys().Int8Array.prototype.lastIndexOf()Returns the last(greatest)index of an element within the array equal to the specified value, or -1 if none is found. See also Array.prototype.lastIndexOf().Int8Array.prototype.map()返回一个由回调函数的返回值组成的新数组。. See also Array.prototype.map().Int8Array.prototype.move()未实现Int8Array.prototype.copyWithin()早期的不标准定义。Int8Array.prototype.reduce()从左到右为每个数组元素执行一次回调函数,并把上次回调函数的返回值放在一个暂存器中传给下次回调函数,并返回最后一次回调函数的返回值。参照Array.prototype.reduce().Int8Array.prototype.reduceRight()从右到左为每个数组元素执行一次回调函数,并把上次回调函数的返回值放在一个暂存器中传给下次回调函数,并返回最后一次回调函数的返回值。参照Array.prototype.reduceRight().Int8Array.prototype.reverse()颠倒数组中元素的排列顺序,即原先的第一个变为最后一个,原先的最后一个变为第一个。参照Array.prototype.reverse().Int8Array.prototype.set()Stores multiple values in the typed array, reading input values from a specified array.Int8Array.prototype.slice()抽取当前数组中的一段元素组合成一个新数组。参照Array.prototype.slice().Int8Array.prototype.some()如果数组中至少有一个元素满足测试函数,则返回 true,否则返回 false。参照Array.prototype.some().Int8Array.prototype.sort()对数组元素进行排序,并返回当前数组.参照Array.prototype.sort().Int8Array.prototype.subarray()返回一个以给定的初始结束位置裁剪的Int8Array数组.Int8Array.prototype.values()返回一个数组迭代器对象,该迭代器会包含所有数组元素的值。.参照Array.prototype.values().Int8Array.prototype.toLocaleString()返回一个由所有数组元素组合而成的本地化后的字符串. See also Array.prototype.toLocaleString().Int8Array.prototype.toString()返回一个由所有数组元素组合而成的字符串.参照Array.prototype.toString().Int8Array.prototype[@@iterator]()此方法返回一个带有数组内所有元素的迭代器对象,同Int8Array.prototype.values 。

示例

// 以长度参数构造对象
var int8 = new Int8Array(2);
int8[0] = 42;
console.log(int8[0]); // 42
console.log(int8.length); // 2
console.log(int8.BYTES_PER_ELEMENT); // 1

// 以数组构造对象
var arr = new Int8Array([21,31]);
console.log(arr[1]); // 31

// 从另一数组构造对象
var x = new Int8Array([21, 31]);
var y = new Int8Array(x);
console.log(y[0]); // 21

// 从ArrayBuffer构造对象
var buffer = new ArrayBuffer(8);
var z = new Int8Array(buffer, 1, 4);

鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com

免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)

图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)