Are JavaScript arrays objects? Last Updated : 08 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Yes, JavaScript arrays are actually specialized objects, with indexed keys and special properties. They have a length property and are technically instances of the Array constructor. JavaScript const a = [10, 20, 30]; console.log(typeof a); Outputobject You can add non-integer properties to arrays, making them work partly like objects. However, this is usually discouraged for clarity. JavaScript let a = [1, 2, 3]; // Adding a property to array (NOT RECOMMEMDED IN PRACTICE) a.name = "MyArray"; console.log(a.name); // Iterating through the array with `for...in` // (NOT RECOMMENDED IN PRACTICE) for (let key in a) { console.log(`${key}: ${a[key]}`); } // Despite adding an extra property, arr.length remains 3 // because only numeric indices count toward the length. console.log(arr.length) OutputMyArray 0: 1 1: 2 2: 3 name: MyArray Why it is not recommended to treat arrays like normal objects and add properties?Adding non-integer properties to arrays can lead to unexpected issues:Arrays are typically used to store ordered lists, so adding properties may make code harder to understand.Some iteration methods, like for...in, will include these properties, which might cause bugs.Many array methods (like map, filter, and forEach) only work on elements with numeric indices, so the extra properties won’t be included in these operations.In general, if you need additional properties, it’s better to use an object or another structure instead. Comment More infoAdvertise with us Next Article Are JavaScript arrays objects? K kartik Follow Improve Article Tags : JavaScript Web Technologies javascript-array Similar Reads JavaScript Objects In our previous article on Introduction to Object Oriented Programming in JavaScript we have seen all the common OOP terminology and got to know how they do or don't exist in JavaScript. In this article, objects are discussed in detail.Creating Objects:In JavaScript, Objects can be created using two 6 min read Objects in Javascript An object in JavaScript is a data structure used to store related data collections. It stores data as key-value pairs, where each key is a unique identifier for the associated value. Objects are dynamic, which means the properties can be added, modified, or deleted at runtime.There are two primary w 4 min read Are functions objects in javascript? Yes, Functions are considered first-class objects, which means they have the same capabilities as other objects. The following are examples that demonstrates functions behaving as objects:Can be assigned to variableJavaScript// Assign a function to a variable const x = function() { return `GfG!`; }; 1 min read Are String Objects in JavaScript? Strings in JavaScript are one of the primitive data types, alongside numbers, booleans, null, undefined, bigint, and symbols. Unlike objects, primitives do not have methods or properties of their own. However, when you attempt to call a method or access a property on a string, JavaScript automatical 2 min read How to Access Array of Objects in JavaScript ? Accessing an array of objects in JavaScript is a common task that involves retrieving and manipulating data stored within each object. This is essential when working with structured data, allowing developers to easily extract, update, or process information from multiple objects within an array.How 4 min read Like