Good morning everyone, I have a problem sending an array by an "onclick" method when wanting to show the array sent I get "undefined"
onclick code:
firebase.database().ref("/4/").on("value", (dataSnapshot) => {
dataSnapshot.forEach(function(item){
var valor = item.val();
var td = document.createElement('tr');
var detalle = valor.detail;
var arrayFinal = []
for(var i in detalle){
arrayFinal[i] = detalle[i];
}
console.log(arrayFinal);
td.innerHTML = "<td>" + valor.nombre + "</td>" +" <td> <paper-button class='btn btn-primary' onclick=\"modal("+ arrayFinal +")\" raised> detalle </paper-button></td>" + "<td>" + valor.valor + " <span class='text-danger'> CL$ </span></td>";
document.getElementById("ascap").appendChild(td);
});
});
code of the method that the onclick calls "modal ()"
function modal(results){
console.log(typeof(results));
var newArray = JSON.stringify(results);
console.log(results);
};
impression of the variable arrayFinal:
[detail: "string", dateDoc: "date", datePag: "date", amountDecl: "number", amountTotDoc: "number" ...]
console response of the modal function ():
my-home.html: 480 undefined my-home.html: 482 undefined
I tried to do the JSON.stringify before sending it, but at the time of printing it returns an empty array "{}"
Any ideas, what am I wrong?