I have a problem that I cannot merge two arrays in the same row, I now have two arrays and then I want to merge them because they have the same length
Here are my two arrays that look like
I would like to have an output like this by combining but this is what I have tried
const ar1 = $('input[class=namecheckbox]').map((i, el) => ({id: el.id.slice(2)})).get(); const ar2 = $('.quantity_input').map((i, el) => ({quantity: el.value})).get(); const merge= $('input[class=namecheckbox]').map((i, el) => ({id: el.id.slice(2),quantity: el.value})).get(); console.log(ar1); console.log(ar2); console.log(merge);
Does anyone know how to solve my problem? Thanks in advance
P粉0445262172024-04-04 10:35:25
So you get the wrong value, const merge= $('input[class=namecheckbox]')... Because ar2 gets the data from that selection, $('.quantity_input')...< /p>
This also works,
var merge = []; for(var i = 0; i < ar1.length; i++){ let obj = {id: ar1[i]['id'], quantity: ar2[i]['quantity']}; merge.push(obj); }