JavaScripture
Contribute via GitHub Feedback

Uint8ClampedArray : ArrayBufferView

Uint8ClampedArray is similar to an Array where each item is a 8 bit (1 byte) unsigned integer. Values stored in this array are clamped to the range 0-255. Uint8ClampedArrays cannot change size after creation.

Constructors

new Uint8ClampedArray(length : Number) : Uint8ClampedArray

Creates a new Uint8ClampedArray of the specified length where each item starts out as 0

Example:

Run

Results:

 

new Uint8ClampedArray(array : Array) : Uint8ClampedArray

Creates a new Uint8ClampedArray and copies the items of array into this. The copied items are converted to 8 bit integers before being stored in this.

Example:

Run

Results:

 

new Uint8ClampedArray(array : Uint8ClampedArray) : Uint8ClampedArray

Creates a new Uint8ClampedArray and copies the items of array into this. array can be any of the typed array types and the copied items will be converted to 8 bit integers before being stored in this.

Example:

Run

Results:

 

new Uint8ClampedArray(buffer : ArrayBuffer, [byteOffset = 0 : Number, [length : Number]]) : Uint8ClampedArray

Creates a view on top of the specified buffer starting at byteOffset of length items. Changes to the items in this actual affect the underlying buffer, and vice versa. If length is not specified, this.length will be buffer.length - byteOffset.

Example:

Run

Results:

 

Instance Indexers

this[index : Number] : Number

Gets and sets the element in this at index. index should be between 0 and this.length - 1. Setting an element to a value less than 0 will store 0 and greater than 255 will store 255 in the array.

Example:

Run

Results:

 

Instance Properties

buffer : ArrayBuffer  

Returns the underlying buffer for this Uint8ClampedArray.

Example:

Run

Results:

 

byteLength : Number  

The length of this in bytes.

Example:

Run

Results:

 

byteOffset : Number  

The offset into this.buffer where the 0th item is stored.

Example:

Run

Results:

 

length : Number  

The number of elements in this. It is 1 greater than the index of the last item.

Example:

Run

Results:

 

Instance Methods

copyWithin(target : Number, start : Number, [end : Number]) : undefined

Copies this[start], this[start + 1], ... this[end - 1] to this[target], this[target + 1], ... If end is not specified, this.length is used.

Example:

Run

Results:

 

entries() : Iterator<Array<Number>>

Returns an iterator of the index and items in this where the values of the iterator are of the form [index : Number, item : Number]. See also values() and keys().

Example:

Run

Results:

 

every(callback : Function, [thisArg : Object]) : Boolean
callback(item : Number, index : Number, array : Uint8ClampedArray) : Boolean

Returns true if callback returns true for every item in this. Otherwise returns false. The Uint8ClampedArray passed to callback is the this of the call to every.

Example:

Run

Results:

 

fill(value : Number, [start = 0 : Number, [end : Number]]) : Uint8ClampedArray

Fills this[start], this[start + 1], ... this[end - 1] with value. If end is not specified, this.length is used. Returns this.

Example:

Run

Results:

 

filter(callback : Function, [thisArg : Object]) : Uint8ClampedArray
callback(item : Number, index : Number, array : Uint8ClampedArray) : Boolean

Returns a new Uint8ClampedArray containing only the items in this that callback returned true for. The Uint8ClampedArray passed to callback is the this of the call to filter.

Example:

Run

Results:

 

find(callback : Function, [thisArg : Object]) : Number
callback(item : Number, index : Number, array : Uint8ClampedArray) : Boolean

Returns the first item in this where callback returns true for that item. The Uint8ClampedArray passed to callback is the this of the call to find. See also findIndex().

Example:

Run

Results:

 

findIndex(callback : Function, [thisArg : Object]) : Number
callback(item : Number, index : Number, array : Uint8ClampedArray) : Boolean

Returns the index of the first item in this where callback returns true for that item. The Uint8ClampedArray passed to callback is the this of the call to find. See also find().

Example:

Run

Results:

 

forEach(callback : Function, [thisArg : Object]) : undefined
callback(item : Number, index : Number, array : Uint8ClampedArray) : undefined

Calls callback for each item in this. The Uint8ClampedArray passed to callback is the this of the call to forEach.

Example:

Run

Results:

 

includes(item : Number, [startingIndex = 0 : Number]) : Boolean

Returns true if item is an element of this starting the search from startingIndex. If startingIndex is negative, this.length is added to it before starting the search.

Example:

Run

Results:

 

indexOf(item : Number, [startingIndex = 0 : Number]) : Number

Returns the first location of item in this starting the search from start. If startingIndex is negative, this.length is added to it before starting the search. Returns -1 if item is not found. See also lastIndexOf().

Example:

Run

Results:

 

join([separator = ',' : String]) : String

Returns a String created by joining the toString() of each item of this separated by separator.

Example:

Run

Results:

 

keys() : Iterator<Number>

Returns an iterator of the indicies in this. See also entries() and values().

Example:

Run

Results:

 

lastIndexOf(item : Number, [startingIndex : Number]) : Number

Returns the location of item by searchig backwards through this, starting the search from startingIndex. If startingIndex is not specified, the search starts from the end of the array. If startingIndex is negative, this.length is added to it before starting the search. Returns -1 if item is not found. See also indexOf().

Example:

Run

Results:

 

map(callback : Function, [thisArg : Object]) : Array
callback(item : Number, index : Number, array : Uint8ClampedArray) : Object

Returns a new Uint8ClampedArray with where each item is the result of calling callback on each item in this. The Uint8ClampedArray passed to callback is the this of the call to map.

Example:

Run

Results:

 

reduce(callback : Function, [initialValue : Object]) : Object
callback(previous : Object, current : Number, index : Number, array : Uint8ClampedArray) : Object

Calls callback for each item in this in ascending order (0 to length-1). It passes the return value of callback for the i-1th item as the previous parameter for the ith item. Returns the result from the last call to callback. If initialValue is not specified, callback will first be called on this[1] with previous set to this[0]. The Uint8ClampedArray passed to callback is the this of the call to reduce.

Example:

Run

Results:

 

reduceRight(callback : Function, [initialValue : Object]) : Object
callback(previous : Object, current : Number, index : Number, array : Uint8ClampedArray) : Object

Calls callback for each item in this in descending order (length-1 to 0). It passes the return value of callback for the i+1th item as the previous parameter for the ith item. Returns the result from the last call to callback. If initialValue is not specified, callback will first be called on this[this.length - 2] with previous set to this[this.length - 1]. The Uint8ClampedArray passed to callback is the this of the call to reduceRight.

Example:

Run

Results:

 

reverse() : Uint8ClampedArray

Reverses the order of the items in this and returns this.

Example:

Run

Results:

 

set 2 variants
set(array : Array, [offset = 0 : Number]) : undefined

Copies items from array into this starting at this[offset]. Copied items are converted to 8 bit ints before storing in this.

Example:

Run

Results:

 

set(array : Uint8ClampedArray, [offset = 0 : Number]) : undefined

Copies items from array into this starting at this[offset]. array can be any of the typed array types and the copied items will be converted to 8 bit ints before storing in this.

Example:

Run

Results:

 

slice(start : Number, [end : Number]) : Uint8ClampedArray

Returns a new Uint8ClampedArray which is composed of the items this[start], this[start + 1], ..., this[end - 1]. Note that item[end] is not included. If start or end is negative, the value is added to this.length before performing the slice. If end is not specified, this.length is used.

Example:

Run

Results:

 

some(callback : Function, [thisArg : Object]) : Boolean
callback(item : Number, index : Number, array : Uint8ClampedArray) : Boolean

Returns true if callback returns true for at least one item in this. Otherwise returns false. The Uint8ClampedArray passed to callback is the this of the call to some.

Example:

Run

Results:

 

sort([comparisonFunction : Function]) : Uint8ClampedArray
comparisonFunction(x : Number, y : Number) : Number

Sort the items of this using comparisonFunction to determine the sort order and returns this. The Number returned by comparisonFunction should be 0 if x and y are equal, negative if x is less than y, or positive if x is greater than y. If comparisonFunction is not specified, the items will be sorted in numeric order. Returns this.

Example:

Run

Results:

 

subarray(begin : Number, [end : Number]) : Uint8ClampedArray

Returns a new Uint8ClampedArray that is a view on top of this containing items this[begin], this[begin + 1], ..., this[end - 1]. The 0th item in the returned array in the same memory location as this[begin]. If end is not specified, this.length is used.

Example:

Run

Results:

 

values() : Iterator<Number>

Returns an iterator of the items in this. The values function is also returned for this[Symbol.iterator] so you can iterate over this directly to get the values. See also entries() and keys().

Example:

Run

Results:

 

Uint8ClampedArray Properties

BYTES_PER_ELEMENT : Number

Returns the size in bytes of an item in a Uint8ClampedArray.

Example:

Run

Results: