The exemploLista
that you are using and is created with the {...}
notation is an object and not a array . In javascript objects are basically hash maps ({key: value}) and according to the specification that defines the syntax / language rules an object is "an unordered collection of properties with values".
So the way you built your
exemploLista
object there is no way to leave it in any desired order, you should consider that the values will always go out in random order, the fact that you have tested them and the values have been printed on the The order in which you put them in the object (
Object {Igor: "exemplo1.jpg", Joao: "exemplo2.jpg", Lucas: "exemplo3.jpg"}
) can be considered pure chance and can (read it goes) vary according to the browser even according to the version of it.
If you want to ensure order a good option is to use arrays true, an outline of how you could do what you want:
var exemploLista = [];
exemploLista[1] = {nome: "Igor", imagem: "exemplo1.jpg"};
exemploLista[2] = {nome: "Joao", imagem: "exemplo2.jpg"};
exemploLista[0] = {nome: "Lucas", imagem: "exemplo3.jpg"};
In the code above Lucas would be added last but would be in the first position of the array. To remove "Lucas" from the array if it already existed before being added you need to iterate over the exampleList array, check at each position if there is an object named Lucas, remove if there is and after the end of the loop add lucas in the desired position . Note that you would also have to rearrange the positions of the array so it does not look like empty elements. I will not add any more code and explanations because the answer is already quite long so I suggest you read the links about objects and arrays I passed so you can understand the difference and then post a new, more specific question if you still need it.