Interview Question

Difference between array and object?

Arrays are specialized indexed objects; ordinary objects are general property collections.

💡 Concept ✅ Quick Revision ⚡ JavaScript

Answer

Arrays and ordinary objects are both objects, but arrays add indexed collection behavior. • Arrays have a length property tied to array-index keys. • Ordinary objects are general keyed records without Array length rules. • Use Array.isArray rather than typeof to distinguish an array.

Example

Code
console.log(typeof []);
console.log(Array.isArray([]));
Output
object
true

Quick Revision

Arrays are specialized indexed objects; ordinary objects are general property collections.