Good afternoon guys from Stack Overflow.
I'm having a hard time getting content from a specific array in javascript.
In the first few lines of javascript code it looks like this. Loose
var arrayIDs = [];
After a while, it runs the following code
$(".form-group").find('*').each(function() {
var id = $(this).attr("id");
if ($("#" + id).val() > 0) {
if ($("#" + id).data("id-produto-item") != undefined) {
arrayIDs.push({
id_produto_itens: $("#" + id).data("id-produto-item"),
id_proposta: numeroProposta
});
}
}
});
After the data is filled, I eventually need to manipulate them.
When I give a console.log in arrayIDs, this appears to me:
*→ []
→ 0: {id_produto_itens: 150, id_proposta: "123"}
→ 1 : {id_produto_itens: 160, id_proposta: "123"}
→ 2: {id_produto_itens: 176, id_proposta: "123"}
→ 3: {id_produto_itens: 175, id_proposta: "123"}
length: 4__proto__: Array(0)*
The problem occurs when I want to scroll through the values as follows, so that it does not even go into the $ .each
It does not display an error message or anything, then when I put a console.log ("message") nor enter that "message"
$(document).on('click','#btnSalvar',function () {
$.each(arrayIDs, function (key, value) {
console.log("mensagem")
console.log(arrayIDs.id_produto_itens);
});
});
The question is, how do you get the contents of this array?
Edit 1: I'll put it exactly when each snippet is called