"Array is an ordered list"

I was surprised to hear (in the last lecture of chap 1) that an array is an ordered list. In the example cited in the lecture, the values are indeed in alphabetical order. In the data available to me, the values are not in alphabetical order. Was that a mispeak on the part of the lecturer? Do array elements have to indeed be in a specific order?

Hey @Jack_65930

An array is an ordered list in the sense that it will maintain the same order when called for. And that order is the order in which items were put into the array.

Consider the following:

const array1 = [ 1, 2, 3, 4, 5 ] 
const array2 = [ 3, 2, 5, 1, 4 ]

console.log(array1) // [ 1, 2, 3, 4, 5 ]
console.log(array2) // [ 3, 2, 5, 1, 4 ]

So the order is maintained. The array does not sort the data itself.

I would recommend you take a look at this

Hi @Jack_65930,

In addition to @natac13,

Here the term ordered does not mean sorted order rather it mean the data is stored in the same order in which it was inserted into the array and no internal shuffling of the data takes places by itself.

It was just a coincidence that the data was somewhat alphabetically ordered.

I hope it helps. If you have any other issue, please feel free to get back to us.

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer