Excuse my english, im from argentina.
I have an object in JS
called listaTurnos
(obtained from a ajax
call)
var listaTurnos = []
$(document).ready(function() {
$.ajax({
type: 'POST',
url: 'ajax/turnos2.ajax.php',
dataType: "json",
data: { item: "a" },
success: function(data) {
data.forEach(e => {
listaTurnos.push(e["datos"])
});
},
error: function(data) {
}
});
});
console.log(listaTurnos)
This is how it looks in the console:
[]
0: "{"title":"Agustin Guerra","start":"2020-03-12T10:30:00","end":"2020-03-12T11:30:00"}
↵"
1: "{"title":"Mariel Guerrieri","start":"2020-03-15T09:30:00","end":"2020-03-15T10:30:00"}
↵"
length: 2
__proto__: Array(0)
I don't know how get the values {"title":"Agustin Guerra","start":"2020-03-12T10:30:00","end":"2020-03-12T11:30:00"}
for example.
I try with for..in
, with foreach
and for
, without success.
listaTurnos.forEach(e => {
console.log(e.title)
// etc
});
Returns nothing
console.log(JSON.stringify(listaTurnos))
Returns []
for (let i = 0; i < listaTurnos.length; i++) {
console.log(listaTurnos[i])
}
Returns nothing
I'm really lost
my goal is, from the object, to get the following structure
[
{
title: 'Agustin Guerra',
start: '2020-03-12T10:30:00',
end: '2020-03-12T11:30:00'
},
{
title: 'Mariel Guerrieri',
start: '2020-03-15T09:30:00',
end: '2020-03-15T10:30:00'
}
]