Preserving the Order in Arrays
The problem with iterating over objects is that the order of iteration can vary. We will use State Object Normalization to solve this.
We'll cover the following...
Caveat #2 : Preservation of Order.
This is perhaps the number one reason people use arrays. Arrays preserve the order of their values.
You have to see an example to understand this.
const numbers = [0,3,1,6,89,5,7,9]
Whatever you do, fetching the value of numbers will always return the same array, with the order of the inputs unaltered.
How about an object? Try it out below.
Press + to interact
const numbers = {0: "Zero",3: "Three",1: "One",6: "Six",89: "Eighty-nine",5: "Five",7: "Seven",9: "Nine"};console.log(numbers);
The order of the object values aren’t returned in the same way!
Now, depending on the kind of ...