I am using an associative array to reflect a list of LI elements:
var array = []
array["cats"] = {k: "cats", v: "meow"};
array["dogs"] = {k: "dogs", v: "woof"};
array["mice"] = {k: "mice", v: "eek"};
I need to keep the order of the array elements to match the order of the LI elements. if I reorder the LI elements (e.g. move mice to the 2nd position in the list), I want to reorder the array so that I can do the following and see the the same order:
for (var i in array){
console.log(i);
}
and produce the output:
cats
mice
dogs
Since it is associative, I cannot use the splice
method. How can I accomplish this?