I have a JSON object that starts when the page loads, for example:
data[foo] = bar; data[foo2] = bar2; data[foo3] = bar3;
Is there a way to insert an element before the first element of foo , so that when for var i in data is executed, the new element will loop to the elements that were added when the object started?
The reason is because I show some elements to the user. When the user adds a new element through javascript, I want this new element to appear above all existing elements, however, when I add a new element, for example,
data[newItem] = newItem;
Then the JSON object looks like this:
data[foo] = bar; data[foo2] = bar2; data[foo3] = bar3; data[newItem] = newItem;
Instead what I want is:
data[newItem] = newItem; data[foo] = bar; data[foo2] = bar2; data[foo3] = bar3;
Any ideas?
Click upvote
source share