Movatterモバイル変換


[0]ホーム

URL:


Menu
×
See More 
Sign In
+1 Get Certified Upgrade For Teachers Spaces Get Certified Upgrade For Teachers Spaces
   ❮     
     ❯   

Basic JavaScript

JS TutorialJS SyntaxJS VariablesJS OperatorsJS If ConditionsJS LoopsJS StringsJS NumbersJS FunctionsJS ObjectsJS DatesJS ArraysJS Typed ArraysJS SetsJS MapsJS MathJS RegExpJS Data TypesJS ErrorsJS EventsJS ProgrammingJS ReferencesJS Versions

JS Advanced

JS FunctionsJS ObjectsJS ClassesJS IterationsJS AsynchronousJS ModulesJS Meta & ProxyJS HTML DOMJS WindowsJS Web APIJS AJAXJS JSONJS jQueryJS GraphicsJS ExamplesJS Reference


Typed Array Methods


The from() Method

Thefrom()method creates a new typed array from any iterable object:

Examples

Create a typed array from a string:

const myArr = Int16Array.from("1234567890");
Try it Yourself »

Create a typed array from an array:

const myArr = Int16Array.from([1,2,3,4,5,6,7,8,9,0]);
Try it Yourself »

The of() Method

Theof() method creates a new typed array from a number of arguments:

Example

const myArr = Int16Array.of(1,2,3,4,5,6,7,8,9,0);
Try it Yourself »

The constructor.name Property

Theconstructor.name property returns the name (type) of a typed array:

Example

myArr.constructor.name
Try it Yourself »

The BYTES_PER_ELEMENT Property

BYTES_PER_ELEMENT returns the number of bytes used to store each array element:

Example

myArr.BYTES_PER_ELEMENT
Try it Yourself »

Common Array Methods

Typed Arrays share many methods withStandard Arrays:

  • Iteration: forEach(), map(), filter(), reduce(), reduceRight(), every(), some(), find(),findIndex(), findLast(), findLastIndex().

  • Searching: includes(), indexOf(), lastIndexOf().

  • Manipulation: at(), copyWithin(), fill(), reverse(), set(), slice(), sort(), subarray().

  • Conversion: join(), toLocaleString(), toString().

  • Non-mutating methods: toReversed(), toSorted(), with().


The fill() Method

Thefill() method changes all elements in a typed array to a value:

Example

Fillall array elements with a value:

myArr.fill(200);
Try it Yourself »

Thefill() method takes two optional arguments: start index and end index:

Example

Fillsome array elements with a value:

myArr.fill(200, 0, 3);
Try it Yourself »

The find() Method

Thefind() method returns the first element that satisfies a test:

Example

myArr.find((x) => x > 18)
Try it Yourself »

The some() Method

Thesome() method returns true if an element for which a provided function returns true:

Example

myArr.some((x) => x > 18)
Try it Yourself »


Not Available Array Methods

Some array methods are NOT available for typed array.

This is due to the fixed-length nature and the lack of fixed structure.

MethodArrayTyped Array
pop()YesNO
push()YesNO
shift()YesNO
unshift()YesNO
splice()YesNO
flat()YesNO
flatMap()YesNO
concat()YesNO
toSpliced()YesNO

Browser APIs Supporting Typed Arrays

Fetch API Example

fetch(url)
.then(request => request.arrayBuffer())
.then(arrayBuffer =>...);

Canvas Example

const canvas = document.getElementById('my_canvas');
const context = canvas.getContext('2d');
const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
const uint8ClampedArray = imageData.data;

Browser Support

Typed Arrays is anES6 feature.

ES6 is fully supported in all modern browsers since June 2017:

Chrome
51
Edge
15
Firefox
54
Safari
10
Opera
38
May 2016Apr 2017Jun 2017Sep 2016Jun 2016


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted ourterms of use,cookies andprivacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved.W3Schools is Powered by W3.CSS.


[8]ページ先頭

©2009-2025 Movatter.jp