javascript Uint8Array

Uint8Array表示8bit unsigned integers向量,初始化为0

构造

new Uint8Array(); // new in ES2017
new Uint8Array(length);
new Uint8Array(typedArray);
new Uint8Array(object);
new Uint8Array(buffer [, byteOffset [, length]]);

属性

Uint8Array.prototype.constructor|
Uint8Array.prototype.buffer|
Uint8Array.prototype.byteLength |字节的长度
Uint8Array.prototype.length|元素的长度

方法

方法 描述
Uint8Array.prototype.copyWithin()
Uint8Array.prototype.entries()
Uint8Array.prototype.every()
Uint8Array.prototype.fill()
Uint8Array.prototype.filter()
Uint8Array.prototype.find()
Uint8Array.prototype.findIndex()
Uint8Array.prototype.forEach()
Uint8Array.prototype.includes()
Uint8Array.prototype.indexOf()
Uint8Array.prototype.join()
Uint8Array.prototype.keys()
Uint8Array.prototype.lastIndexOf()
Uint8Array.prototype.map()
Uint8Array.prototype.reduce()
Uint8Array.prototype.reduceRight()
Uint8Array.prototype.reverse()
Uint8Array.prototype.set()
Uint8Array.prototype.slice()
Uint8Array.prototype.some()
Uint8Array.prototype.sort()
Uint8Array.prototype.subarray()
Uint8Array.prototype.values()
Uint8Array.prototype.toLocaleString()
Uint8Array.prototype.toString()
Uint8Array.prototype@@iterator

例子

// From a length
var uint8 = new Uint8Array(2);
uint8[0] = 42;
console.log(uint8[0]); // 42
console.log(uint8.length); // 2
console.log(uint8.BYTES_PER_ELEMENT); // 1

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

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

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

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

参考:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
https://www.jb51.net/article/147112.htm
https://developer.51cto.com/art/201704/536718.htm

发布了1794 篇原创文章 · 获赞 582 · 访问量 154万+

猜你喜欢

转载自blog.csdn.net/claroja/article/details/104294345
今日推荐