Constructor
new Int8Array(argopt, offsetopt)
Constructs a new Int8Array, which is a typed array. These typed array classes allow Mildew programs to manipulate real binary data.
If arg is missing, creates one with 0 elements. If arg is an integer, creates one with that many elements. If arg is an iterable, creates an array out of the iteration elements. If arg is an ArrayBuffer, creates an array from the raw bytes in the ArrayBuffer, and a second argument can be specified as the offset into the ArrayBuffer to start the new array.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arg |
* |
<optional> |
See description |
offset |
integer |
<optional> |
If arg is an ArrayBuffer, this is the offset into the ArrayBuffer. |
Members
(static) BYTES_PER_ELEMENT :integer
The number of bytes of each element in this type of array.
Type:
(static) name :String
Describes the name of this class
Type:
buffer
Creates an ArrayBuffer out of this typed array.
byteLength
Gets the number of bytes of this typed array. This is the size of each element multiplied by the
number of array elements.
byteOffset
Gets the offset if this typed array into the original ArrayBuffer if this typed array was constructed
with two arguments, otherwise 0.
length
Returns the number of elements in this array.
Methods
(static) from(iterable, callbackopt, thisToUseopt) → {Int8Array}
Creates a new typed array from an Array, String, Generator, or other typed array by
appending each element or calling the callback on each element and adding the return value.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
iterable |
* | Any iterable object | |
callback |
function |
<optional> |
The optional callback that receives the element, index, and typed array. |
thisToUse |
* |
<optional> |
The "this" object inside the callback. |
Returns:
A new typed array created from the parameters.
- Type
- Int8Array
(static) isView() → {boolean}
This static method always returns true because all typed arrays are modifiable views of ArrayBuffers.
Returns:
True.
- Type
- boolean
(static) of(…var_args) → {Int8Array}
Creates a Int8Array out of all the parameters.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
var_args |
* |
<repeatable> |
A list of values |
Returns:
A new typed array from the list of values.
- Type
- Int8Array
at(index)
Retrieves an element at a given index. Index can be negative, in which case it is added to the length.
Parameters:
Name | Type | Description |
---|---|---|
index |
integer | The index into the typed array. |
copyWithin(target, startopt, endopt) → {Int8Array}
Copies elements within this typed array from start to end starting at the position specified by target.
Returns a reference to this typed array
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
target |
integer | Where the copying should start | ||
start |
integer |
<optional> |
0 | Where the elements to copy start |
end |
integer |
<optional> |
this.length | The upper bound of the elements to copy |
Returns:
this typed array, which has been modified in place.
- Type
- Int8Array
entries() → {Generator}
Returns an iterator whose iteration value is an Array containing first the index and second the value of each
entry in this array.
Returns:
An iterator.
- Type
- Generator
every(func, thisToUseopt) → {boolean}
Tests every element of this typed array by calling func on each element
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
func |
function | The function that should take an array element as a parameter and return a boolean. The function may also receive the index of the current element as well as the typed array itself. | |
thisToUse |
* |
<optional> |
The "this" object for inside the callback function. Defaults to undefined |
Returns:
True if every call to func returns true, otherwise false
- Type
- boolean
fill(value, startopt, endopt) → {Int8Array}
Sets the elements in this typed array to value starting at start and stopping at end-1
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
* | The value to fill this typed array with | ||
start |
integer |
<optional> |
0 | The position to start filling |
end |
integer |
<optional> |
this.length | The position to stop |
Returns:
This typed array, now modified.
- Type
- Int8Array
filter(func, thisToUseopt) → {Int8Array}
Creates a new typed array based on return value of func
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
func |
function | A function that receives an element and should return a boolean. The function may also receive the index and this typed array. | |
thisToUse |
* |
<optional> |
The "this" value inside the callback. |
Returns:
A typed array of elements that func(element) returned true for.
- Type
- Int8Array
find(func, thisToUseopt) → {*}
Finds the first element that satisfies the search condition of the callback.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
func |
function | The callback that should return true if its first parameter matches the criteria. This callback can also receive the index and this typed array. | |
thisToUse |
* |
<optional> |
The "this" object to use inside the callback. |
Returns:
The first element found by the function or undefined if nothing was found.
- Type
- *
findIndex(func, thisToUseopt) → {integer}
Finds the index of the first element that satisfies the search condition of the callback.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
func |
function | The callback that should return true if its first parameter matches the criteria. This callback also receives the index and typed array. | |
thisToUse |
* |
<optional> |
The "this" value to use inside the callback. |
Returns:
The index of the first element found, or -1 if not found.
- Type
- integer
forEach(callback, thisToUseopt)
Calls a function on each element in order.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
function | The function to call on each element. Also receives index and the typed array. | |
thisToUse |
* |
<optional> |
The "this" object to use inside the callback |
includes(item, indexopt) → {boolean}
Tests if this typed array includes an equal item. Starts searching at index.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
* | Item to look for. This should be of the type of the array elements. | ||
index |
integer |
<optional> |
0 | Where in this typed array to start searching |
Returns:
True if the item is in the typed array otherwise false
- Type
- boolean
indexOf(item, startopt) → {integer}
Searches for the index of a specific item. Starts searching at start
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
* | Item to search for. This should be of the type of the array elements. | ||
start |
integer |
<optional> |
0 | Where in this typed array to start searching |
Returns:
The index of the first item that matches, or -1 if not found
- Type
- integer
isView() → {boolean}
This method always returns true because all typed arrays are modifiable views of ArrayBuffers.
Returns:
True.
- Type
- boolean
join(delimopt) → {String}
Converts all elements of this typed array to String, placing the delimiter parameter between them.
If no delimiter is specified, a comma (",") is used.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
delim |
String |
<optional> |
"," | The delimiter to place between joined strings |
Returns:
A string concatenation of all typed array elements with delim between them.
- Type
- String
keys() → {Generator}
Gets an iterator that iterates over each integer index in this typed array
Returns:
An iterator that iterates over each integer index.
- Type
- Generator
lastIndexOf(item, startopt) → {integer}
Searches for an item through the typed array backwards starting at the end
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
* | The item to search for. This should be of the type of the array elements. | ||
start |
integer |
<optional> |
this.length-1 | The location in the typed array to start the backwards search |
Returns:
The index of the located item, or -1 if not found.
- Type
- integer
map(callback, thisToUseopt) → {Int8Array}
Creates a new Int8Array by calling a callback on every element in this typed array
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
function | A function that accepts the element, index, and typed array and returns an item to be added to the new typed array | |
thisToUse |
* |
<optional> |
The "this" object inside the callback |
Returns:
A new typed array made of the return values of the callback
- Type
- Int8Array
reduce(callback, initialValueopt) → {*}
Reduces a typed array to a single accumulated value using the callback on each element. It is an error
to call reduce on an empty typed array without providing an accumulator parameter.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
callback |
function | Receives the accumulator value, the current element, index, and typed array. Its return value becomes the accumulator between each call. Note, the first element is not applied if an accumulator is provided. | ||
initialValue |
* |
<optional> |
this.at(0) | The initial value for the accumulator, defaults to the first element of the typed array |
Returns:
The accumulated value
- Type
- *
reduceRight(callback, initialValueopt) → {*}
Similar to reduce but works from right to left of the typed array. It is an error to call reduceRight on an
empty typed array without providing an accumulator parameter.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
callback |
function | The callback receives the accumulator value, current element, index and typed array and returns the next accumulator value. Note, the first element is not applied if an accumulator is provided. | ||
initialValue |
* |
<optional> |
this.at(-1) | The initial accumulator value. Defaults to the last typed array element. |
Returns:
The accumulated value
- Type
- *
reverse() → {Int8Array}
Reverses this typed array in place and returns itself.
Returns:
this typed array, now reversed.
- Type
- Int8Array
set(iterable, offsetopt)
Converts the iterable argument to an Array and copies each element to this typed array starting at the
offset. It is an error for the iterable Array size to exceed the typed array length minus the offset.
This method is not optimized in any way.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
iterable |
* | Any iterable object. | ||
offset |
integer |
<optional> |
0 | The offset into this typed array where the copying should start. |
slice(startopt, endopt) → {Int8Array}
Returns a copied slice of this typed array ranging from start to end - 1 inclusive.
If only one parameter is given, returns a slice from the first parameter to the end of the typed array.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
start |
integer |
<optional> |
0 | See description |
end |
integer |
<optional> |
this.length | See description |
Returns:
A typed array consisting of elements in the given range. This new typed array is
a copy.
- Type
- Int8Array
some(callback, thisToUseopt) → {boolean}
Returns true if at least one element in the typed array matches the condition of the callback.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
function | Returns a boolean. Receives the element, index, and typed array. | |
thisToUse |
* |
<optional> |
The this object to use in the callback. |
Returns:
True if at least one element matches the callback's condition, otherwise false.
- Type
- boolean
sort(sorteropt) → {Int8Array}
Sorts this typed array in place and returns it. An optional sorting function can be provided which should
receive two values and return -1, 0, or 1 based on comparison.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
sorter |
function |
<optional> |
An optional function that receives an element and the next element. |
Returns:
this typed array, now sorted.
- Type
- Int8Array
subarray(start, end) → {Int8Array}
This method works like slice except no copying is done such that modifications to the return value
affect the original typed array.
Parameters:
Name | Type | Description |
---|---|---|
start |
integer | The index into this typed array at which to start the slice |
end |
integer | The index into this typed array at which to stop the slice |
Returns:
A typed array that is a subarray of this typed array.
- Type
- Int8Array
values() → {Generator}
Gets an iterator that iterates over each value in this typed array.
Returns:
An iterator that iterates over each value.
- Type
- Generator