Javascript - Typed Arrays and Normal Arrays

Introduction

Typed arrays and Normal arrays are similar in some ways:

  • they both have length property, and
  • elements in the array can be accessed using the [ ] operator.
  • typed arrays support all standard array methods.

Typed arrays in JavaScript requires that all the elements of an array are of the same type.

Typed arrays cannot have empty elements. They are always initialized with a 0 value.

const buffer = new ArrayBuffer(16); 
const float32View = new Float32Array(buffer); 
let arr = new Array(10); 

console.log(float32View); // Float32Array [0, 0, 0, 0] 
console.log(arr); // [,,,,,,,,,] 

Related Topic