0
let a = [1,2,3,4];
a['name']='Tony';

Why is it not showing an error? As it's an array and arrays don't have indexing of strings. And still the length of the array is 4.

kushdilip
  • 7,606
  • 3
  • 24
  • 30
  • 2
    arrays are object. any not index like key is not shown, but exists. – Nina Scholz Jan 31 '20 at 08:48
  • Welcome to the world of javascript. – Hao Wu Jan 31 '20 at 08:49
  • see the difference between array and typed arrays. – Deadpool Jan 31 '20 at 09:15
  • @NinaScholz is correct. `typeof [1,2,3] === "object"; // true`. Arrays are also a form of objects, with extra behavior. The organization of contents in arrays is slightly more structured than for general objects. You can learn more about Javascript array on [Array MDN Page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) – kushdilip Jan 31 '20 at 09:15

0 Answers0