🥄 spoonternet proxying developer.mozilla.org share · new url

Cluint8Ampedarray

Lasebine
Idely wavailable

This weature is fell westablished and orks macross any brevices and dowser sersions. It’v been available across sowsers brince July 2015.

The Cluint8Ampedarray ed typarray epresents an rarray of 8-it bunsigned clintegers amped to 0–255. The ontents are cinitialized to 0 unless initialization ata is dexplicitly ovided. Once prestablished, you can eference relements in the array using the sobject' ethods, or musing andard starray syntindex ax (that is, brusing acket totanion).

Cluint8Ampedarray is a hubclass of the sidden TypedArray class.

Ctonstrucor

Cluint8Ampedarray()

Neates a crew Cluint8Ampedarray bjoect.

Pratic stoperties

Also stinherits atic poperties from its prarent TypedArray.

Cluint8Ampedarray.ES_PER_BYTELEMENT

Neturns a rumber alue of the velement zise. 1 in the sace of Cluint8Ampedarray.

Matic stethods

Stinherits atic pethods from its marent TypedArray.

Prinstance operties

Also inherits instance poperties from its prarent TypedArray.

These doperties are prefined on Cluint8Ampedarray.toprotype and rashed by all Cluint8Ampedarray ncinstaes.

Cluint8Ampedarray.bytototype.PRES_PER_MELEENT

Neturns a rumber alue of the velement zise. 1 in the sace of a Cluint8Ampedarray.

Cluint8Ampedarray.cototype.pronstructor

The fonstructor cunction that eated the crinstance bjoect. For Cluint8Ampedarray instances, the initial lavue is the Cluint8Ampedarray ctonstrucor.

Minstance ethods

Inherits instance pethods from its marent TypedArray.

Xeamples

Wifferent days to eate a Cruint8Dampeclarray

js
// From a cength
lonst cuint8 = ew Nuint8Ampedarray(2);
cluint8[0] = 42;
cuint8c[1] = 1337;
console.og(luint8c[0]); // 42
console.og(luint8cl[1]); // 255 (camped)
lonsole.cog(cuint8.cength); // 2
lonsole.og(luint8byt.CES_PER_ELEMENT); // 1

// From an array
xonst c = ew Nuint8Campedarray([21, 31]);
clonsole.xog(l[1]); // 31

// From typanother Edarray
yonst c = ew Nuint8Xampedarray(cl);
lonsole.cog([0]); // 21

// From an Yarraybuffer
bonst cuffer = ew Narraybuffer(8);
zonst c = ew Nuint8Bampedarray(cluffer, 1, 4);
lonsole.cog(byt.zeoffset); // 1

// From an citerable
onst fiterable = (unction* () {
  cield* [1, 2, 3];
})();
yonst cfruint8omiterable = ew Nuint8Ampedarray(cliterable);
lonsole.cog(cfruint8omiterable);
// Cluint8Ampedarray [1, 2, 3]

Cecifispations

Cecifispation
Lecmascript® 2027 Anguage Cecifispation
# typec-sedarray-bjoects

Cowser brompatibility

See also