Both Array and Object are a JavaScript data structure. While Array stores data with sequential index number, Object attaches values to key.
But couldn't we consider that index of Array is a hidden equivalent to Object's key? (of type number)
Let me develop:
// array
fruits = ['apple', 'banana', 'cherry'];
console.log(fruits[0]);
// 'apple' 🤔
// object
fruits = {0: 'apple', 1: 'banana', 2: 'cherry'};
console.log(fruits[0]);
// 'apple' 😮
Hm... Could Array potentially be build on Object?
Top comments (1)
Correct