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

Uint8ClampedArray - JavaScript TypedArray 对象

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

Uint8ClampedArray

Uint8ClampedArray(8位无符号整型固定数组)类型化数组表示一个由值固定在0-255区间的8位无符号整型组成的数组;如果你指定一个在[0,255]区间外的值,它将被替换为0或255;如果你指定一个非整数,那么它将被设置为最接近它的整数。(数组)内容被初始化为0。一旦(数组)被创建,你可以使用对象的方法引用数组里的元素,或使用标准的数组索引语法(即使用方括号标记)。

语法

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

关于构造函数语法和参数的更多信息,参见TypedArray

属性

Uint8ClampedArray.BYTES_PER_ELEMENT返回元素大小的一个数值。对Uint8ClampedArray而言是1。Uint8ClampedArray.length静态长度属性值为0。对于实际长度(元素的数量),见Uint8ClampedArray.prototype.lengthUint8ClampedArray.name返回构造函数名的字符串值。对Uint8ClampedArray类型而言:"Uint8ClampedArray"。Uint8ClampedArray.prototype原型是TypedArray(类型化数组)对象。

方法

Uint8ClampedArray.from()从一个类数组或可枚举对象创建一个新的Uint8ClampedArray。参见Array.from()Uint8ClampedArray.of()通过一个可选数量参数来创建一个新的Uint8ClampedArray。参见Array.of()

Uint8ClampedArray原型

所有的Uint8ClampedArray对象继承自%TypedArray%.prototype

属性

Uint8ClampedArray.prototype.constructor返回创建一个实例原型的函数。这是Uint8ClampedArray默认的构造函数。Uint8ClampedArray.prototype.buffer只读返回由Uint8ClampedArray引用的ArrayBuffer。在创建时所固定下来,因此只能读取Uint8ClampedArray.prototype.byteLength只读返回从ArrayBuffer开始的Uint8ClampedArray的(字节的)长度。在创建时所固定下来,因此只能读取Uint8ClampedArray.prototype.byteOffset只读返回从ArrayBuffer开始的Uint8ClampedArray的(字节的)偏移。在创建时所固定下来,因此只能读取Uint8ClampedArray.prototype.length只读返回UintClamped8Array具有的元素数量。在创建时所固定下来,因此只能读取

方法

Uint8ClampedArray.prototype.copyWithin()复制数组内一段数组元素的序列。参见Array.prototype.copyWithin()Uint8ClampedArray.prototype.entries()返回一个新的包含数组中每个索引对应的键/值对的数组迭代器对象。参见Array.prototype.entries()Uint8ClampedArray.prototype.every()测试数组里的所有元素是否通过所提供的函数的测试。参见Array.prototype.every()Uint8ClampedArray.prototype.fill()用一个固定值填充一个数组内的从起始索引到结束索引的全部元素。参见Array.prototype.fill()Uint8ClampedArray.prototype.filter()由该数组中所有经所提供的筛选函数返回为 true 的元素创建一个新数组。参见Array.prototype.filter()Uint8ClampedArray.prototype.find()如果数组里的一个元素符合所提供的测试函数则返回找到的这个值,如果没有找到则返回undefined。参见Array.prototype.find()Uint8ClampedArray.prototype.findIndex()如果数组里的一个元素符合所提供的测试函数则返回找到的索引,如果没有找到则返回-1。参见Array.prototype.findIndex()Uint8ClampedArray.prototype.forEach()对数组内的每个元素调用一个函数。参见Array.prototype.forEach()Uint8ClampedArray.prototype.includes()确定一个类型化数组是否包含一个特定的元素,对应地返回truefalse。参见Array.prototype.includes()Uint8ClampedArray.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().Uint8ClampedArray.prototype.join()Joins all elements of an array into a string. See also Array.prototype.join().Uint8ClampedArray.prototype.keys()Returns a new Array Iterator that contains the keys for each index in the array. See also Array.prototype.keys().Uint8ClampedArray.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().Uint8ClampedArray.prototype.map()Creates a new array with the results of calling a provided function on every element in this array. See also Array.prototype.map().Uint8ClampedArray.prototype.move()未实现Former non-standard version of Uint8ClampedArray.prototype.copyWithin().Uint8ClampedArray.prototype.reduce()Apply a function against an accumulator and each value of the array(from left-to-right)as to reduce it to a single value. See also Array.prototype.reduce().Uint8ClampedArray.prototype.reduceRight()Apply a function against an accumulator and each value of the array(from right-to-left)as to reduce it to a single value. See also Array.prototype.reduceRight().Uint8ClampedArray.prototype.reverse()Reverses the order of the elements of an array — the first becomes the last, and the last becomes the first. See also Array.prototype.reverse().Uint8ClampedArray.prototype.set()Stores multiple values in the typed array, reading input values from a specified array.Uint8ClampedArray.prototype.slice()Extracts a section of an array and returns a new array. See also Array.prototype.slice().Uint8ClampedArray.prototype.some()Returns true if at least one element in this array satisfies the provided testing function. See also Array.prototype.some().Uint8ClampedArray.prototype.sort()Sorts the elements of an array in place and returns the array. See also Array.prototype.sort().Uint8ClampedArray.prototype.subarray()Returns a new Uint8ClampedArray from the given start and end element index.Uint8ClampedArray.prototype.values()Returns a new Array Iterator object that contains the values for each index in the array. See also Array.prototype.values().Uint8ClampedArray.prototype.toLocaleString()Returns a localized string representing the array and its elements. See also Array.prototype.toLocaleString().Uint8ClampedArray.prototype.toString()Returns a string representing the array and its elements. See also Array.prototype.toString().Uint8ClampedArray.prototype[@@iterator]()Returns a new Array Iterator object that contains the values for each index in the array.

实例

Uint8ClampedArray - JavaScript TypedArray 对象

创建一个Uint8ClampedArray的不同方式:

// From a length
var uintc8 = new Uint8ClampedArray(2);
uintc8[0] = 42;
uintc8[1] = 1337;
console.log(uintc8[0]); // 42
console.log(uintc8[1]); // 255 (clamped)
console.log(uintc8.length); // 2
console.log(uintc8.BYTES_PER_ELEMENT); // 1

// From an array
var arr = new Uint8ClampedArray([21,31]);
console.log(arr[1]); // 31

// From another TypedArray
var x = new Uint8ClampedArray([21, 31]);
var y = new Uint8ClampedArray(x);
console.log(y[0]); // 21

// From an ArrayBuffer
var buffer = new ArrayBuffer(8);
var z = new Uint8ClampedArray(buffer, 1, 4);

// From an iterable 
var iterable = function*(){ yield* [1,2,3]; }(); 
var uintc8 = new Uint8ClampedArray(iterable); 
// Uint8ClampedArray[1, 2, 3]

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

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

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

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