Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
JavaScript typedArray.of() Method
Next article icon

TypedArray Introduction

Last Updated : 17 Jan, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

TypedArray demonstrates an array-like view of a binary data buffer. They are introduced in ECMAScript version 6 to handle binary data. There is no keyword reserved ‘TypedArray’, nor is there a directly visible TypedArray constructor.

There are several types of TypedArray shown below with their range, size, web IDL Type, and Equivalent C Type:

Type

Range Value

Size (Bytes)

Web IDL Type

Equivalent C type

Int8Array -128 to 127 1 byte int8_t
Uint8Array 0 to 255 1 octet uint8_t
Uint8ClampedArray 0 to 255 1 octet uint8_t
Int16Array -32768 to 32767  2  short int16_t
Uint16Array 0 to 65535  2  unsigned short  uint16_t
Int32Array -2147483648 to 2147483647  4  long int32_t
Uint32Array 0 to 4294967295  4  unsigned long  uint32_t
Float32Array 1.2×10^-38 to 3.4×10^38  4  unrestricted float  float
Float64Array 5.0×10^-324 to 1.8×10^308  8  unrestricted double  double
BigInt64Array -2^63 to 2^63-1  8  bigint int64_t (signed long)
BigUint64Array 0 to 2^64-1  8  bigint  uint64_t (unsigned long)

Constructor: This object cannot be instantiated directly. Instead, you have to create an instance of an array of a particular type, such as an UInt8Array or a BigInt64Array. 

When creating an instance of a TypedArray(e.g. Int8Array), an Array Buffer instance is also created internally in the memory or, if an ArrayBuffer object is given as a constructor argument, then that argument is used instead. 

We can create the instance of TypedArray by using the ‘new’ keyword with the respective constructor.

Syntax:

new TypedArray();  // Or  new TypedArray(length);  // Or  new TypedArray(typedArray);  // Or  new TypedArray(object);  // Or  new TypedArray(buffer [, byteOffset [, length]]);

TypedArray can be of any type mentioned above.

Parameters: Below are the parameters that TypedArray can take:

  • length: The size of ArrayBuffer to create.
  • typedArray: Type of array to be created.
  • object: When called with the object argument, a new typed array instance is created.
  • buffer, byteOffset, length: When called with a buffer, byte offset, and a length argument, a new typed array view is created that is used to view the specified ArrayBuffer.

Instantiating a TypedArray: Below are some examples that show how to instantiate a TypedArray.

Example 1: In this example, we will initialize a typedArray.

Javascript




const buffer = new ArrayBuffer(8);
  
// Initiating using the constructor
const uint8 = new Uint8Array(buffer);
  
// Output is 8 as we initiated the length with 8
console.log(uint8.length);
 
 

Output:

8

Example 2: In this example, we will initialize a typedArray.

Javascript




const int8 = new Int8Array([0, 0, 0, 0]);
      
int8.fill(4, 1, 3);
console.log(int8);
 
 

Output:

Int8Array(4) [0, 4, 4, 0,   buffer: ArrayBuffer(4),   byteLength: 4, byteOffset: 0,   length: 4,   Symbol(Symbol.toStringTag): 'Int8Array']

Example 3: Checking if the values are contained inside the TypedArray.

Javascript




const int8 = new Int8Array([10, 20, 30, 40, 50]);
      
console.log(int8.includes(20));
      
console.log(int8.includes(20, 3));
 
 

Output:

true  false


Next Article
JavaScript typedArray.of() Method

B

bunnyram19
Improve
Article Tags :
  • JavaScript
  • Web Technologies

Similar Reads

  • JavaScript typedArray.@@iterator
    The typedArray.@@iterator is an inbuilt property in JavaScript which is used to return the initial value of the given typedArray's element. Syntax: arr[Symbol.iterator]() Parameters: It does not accept any parameter because it is a property not a function. Return value: It returns the array iterator
    1 min read
  • Underscore.js _.isTypedArray() Function
    Underscore.js is a JavaScript library that provides a lot of useful functions that help in the programming in a big way like the map, filter, invoke, etc even without using any built-in objects. The _.isTypedArray() function is an inbuilt function in Underscore.js library of JavaScript which is used
    1 min read
  • JavaScript typedArray.of() Method
    The typedArray.of() is an inbuilt function in JavaScript which is used to construct a new typedArray with a variable number of parameters. Syntax: TypedArray.of(element0, element1, ......) Parameters: It accepts parameters of different elements whose typedArray is going to be created. Return value:
    1 min read
  • JavaScript typedArray.set() Method
    The typedArray.set() is an inbuilt function in JavaScript which is used to stores a number of values in the given typedArray. typedArray.set(typedArray, offset) Parameters: It accept two parameters which are specified below- typedarray: It is the source array. offset: It is optional and it is into t
    1 min read
  • JavaScript typedArray.indexOf() Method
    The typedArray.indexOf() is an inbuilt function in JavaScript which is used to return the index of the element if found in the given typedArray otherwise it returns -1. Syntax: typedarray.indexOf(Element, Index); Parameters: It accepts two parameter which are specified below- Element: It is the elem
    2 min read
  • JavaScript typedArray.map() Method
    The typedArray.map() is an inbuilt function in JavaScript which is used to create a new typedArray with the result of a provided function on each element of the given typedArray. Syntax: typedArray.map(callback) Parameters: It accepts a parameter callback function which accept some parameter which a
    1 min read
  • JavaScript typedArray.length() Method
    The typedArray.length is an inbuilt property in JavaScript which is used to return the length of the given typedArray. Syntax: typedArray.length Parameters: It does not accept any parameter because it is a property not a function. Return value: It returns the length of the given typedArray. Example
    2 min read
  • JavaScript typedArray.keys() Method
    The typedArray.keys() is an inbuilt function in JavaScript which is used to return a new array iterator containing the keys for each index of the elements of the given typedArray. Syntax: typedArray.keys() Parameter: This function does not accept anything as parameter. Return value: It returns a new
    1 min read
  • JavaScript typedArray.fill() Method
    The typedArray.fill() is an inbuilt function in JavaScript which is used to fill a value to typedArray from a start index to end index. Syntax: typedarray.fill(value, start, end) Parameters: It takes three parameters that are specified below- value: It is the value to fill with typed array.start: It
    1 min read
  • Java Collection toArray() Method
    The toArray() method of Java Collection returns an array containing elements that are inside the calling collection. This article will discuss the toArray() method, its syntaxes, how it works, and some code examples. Syntax of toArray() MethodObject[] toArray();Return Type: The return type of the ab
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences