Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Basic JavaScript

JS Tutorial JS Syntax JS Variables JS Operators JS If Conditions JS Loops JS Strings JS Numbers JS Functions JS Objects JS Dates JS Arrays JS Sets JS Maps JS Math JS RegExp JS Data Types JS Errors JS Debugging JS Events JS Programming JS References JS UTF-8 Characters JS Versions

JS Advanced

JS Functions JS Objects JS Classes JS Iterations JS Promises JS Modules JS HTML DOM JS Windows JS Web API JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Reference


Typed Array Methods


The from() Method

The from()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

The of() 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

The constructor.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 with Standard 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

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

Example

Fill all array elements with a value:

myArr.fill(200);
Try it Yourself »

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

Example

Fill some array elements with a value:

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

The find() Method

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

Example

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

The some() Method

The some() 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 an ES6 feature.

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

Chrome
51
Edge
15
Firefox
54
Safari
10
Opera
38
May 2016 Apr 2017 Jun 2017 Sep 2016 Jun 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 our terms of use, cookie and privacy policy.

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