I'm having a hard time figuring out this.
So, I am making a site where I need to store the horizontal position of elements in a object with the ID as value. Then I need to sort the object by the key. Later I have to loop though the object and find the closest elements (both before and after).
I am struggling with storing the information. I have it like a variabel.
Is it correct to store it like this:
myObj.x = tempId;
Next, how do I sort the keys? It should sort as a number, not text because I had problem with the sort doing 14, 1500, 800
.
And last, how can I loop the object and maintain access to both key and value? If I do for (var i in obj)
I loose the key-value.