Merge two arrays in the same row JQUERY
P粉610028841
P粉610028841 2024-04-03 14:41:39
0
1
324

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粉610028841
P粉610028841

reply all(1)
P粉044526217

So you get the wrong value, const merge= $('input[class=namecheckbox]')... Because ar2 gets the data from that selection, $('.quantity_input')...

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);
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!