r/learnjavascript • • Jul 20 '21

JavaScript Facts: Object And Array

252 Upvotes

23 comments sorted by

View all comments

21

u/[deleted] Jul 20 '21

[removed] — view removed comment

7

u/FriesWithThat Jul 20 '21

Well, #1 looks to specifically be addressing arrays. I'd say for #1 to be more precise it should say:

The elements in an array are stored as the array's properties, using its index in the array as a property name. The index is of type 'number'.

Length is a property on the array prototype, and is typically accessed using dot notation.

Just to expand, for beginners dropping into that slide:

const arr = [1, 2, 3, 4, 'last element'];
arr[1];  // 2
arr.indexOf(1) // 0
arr[arr.length - 1] // last element
arr.length // 5