Loading lesson path
Concept visual
Start at both ends
method creates a new typed array from any iterable object:
Create a typed array from a string:
const myArr = Int16Array.from("1234567890");Create a typed array from an array:
const myArr = Int16Array.from([1,2,3,4,5,6,7,8,9,0]);method creates a new typed array from a number of arguments:
const myArr = Int16Array.of(1,2,3,4,5,6,7,8,9,0);The constructor.name Property The constructor.name property returns the name (type) of a typed array:
Example myArr.constructor.name The BYTES_PER_ELEMENT Property BYTES_PER_ELEMENT returns the number of bytes used to store each array element:
Example myArr.BYTES_PER_ELEMENT
: forEach(), map(), filter(), reduce(), reduceRight(), every(), some(), find(), findIndex(), findLast(), findLastIndex().
: includes(), indexOf(), lastIndexOf().
: at(), copyWithin(), fill(), reverse(), set(), slice(), sort(), subarray().
: join(), toLocaleString(), toString().
: toReversed(), toSorted(), with().
method changes all elements in a typed array to a value:
Fill all array elements with a value:
myArr.fill(200);method takes two optional arguments: start index and end index:
Fill some array elements with a value:
myArr.fill(200, 0, 3);method returns the first element that satisfies a test:
Example myArr.find((x) => x > 18)method returns true if an element for which a provided function returns true:
Example myArr.some((x) => x > 18)Some array methods are NOT available for typed array.
Formula
This is due to the fixed - length nature and the lack of fixed structure.