I have the following Javascript where I parse data attributes from DOM objects.
I want to zip those two arrays into one, so I get a multidimensional (in this case 2D) array with [[id1, atr1], [id2, atr2], ...]
However, this code below gives me a 1D array with all the ids followed by all the attributes.
I als tried to use map(element, index)
producing the same result.
Can someone help me to zip this correctly?
var currentHTML = $('.product');
var currentId = $("body").find('.product').toArray().map(function(e){return $(e).attr("data-id-product");});
var currentAtr = $("body").find('.product').toArray().map(function(e){return $(e).attr("data-id-product-attribute");});
currentHTMLMap = [];
for(i = 0;i < currentId.length; i++) {
currentHTMLMap.push(currentId[i], currentAtr[i]);
}
Here is how the two 1D arrays could look like:
currentId: ["1", "6"]
currentAtr: ["1", "0"]
Screenshot of my console showing the jQuery 'created' arrays: