I am receiving this array of objects as a callback with a ajax request
[
{"nombre":"Kabul"},
{"nombre":"Qandahar"},
{"nombre":"Herat"},
{"nombre":"Mazar-e-Sharif"},
{"nombre":"Otra"}
]
This is the way I read the array of objects and then press the results in a div
$.ajax({
url:url,
type:"POST",
datatype:"JSON",
contenttype:"application/json",
}).done(function(response){
var text=response;
var obj=JSON.parse(text);
var array=[];
obj.forEach( ciudad => array.push(ciudad.nombre) );
//al imprimir esto en la consola el resultado es exitoso ejemplo
//["kabul","Qandhar","Herat","Mazart-e-Sharif","otra"]
console.log(array)
//trato de imprimir el array en un select de esta manera
for(i=0; i< array.length; i++){
$("#myCities").html(array[i])
}
})
although the push
is successfully done in the array at the time of printing the array in the div
it only prints the last index of the array ie another I do not understand why if the array is fine and I'm assuming that the way I'm reading it with the for
is correct, some help?