Hey, I have this example:
var arr = [['USA', 'Canada'], ['Food', 'Sports']];
and expected result:
arr = [
['USA', 'Food'],
['USA', 'Sports'],
['Canada', 'Food'],
['Canada', 'Sports']
];
Not how I did it, it was like this:
var newArr = [];
$.each(arr[0], function (i, item) {
$.each(arr[1], function (i, thisItem) {
newArr.push([item, thisItem]);
});
});
But this will not work when I add additional elements to the address.
Is there a way to make this recursive, no matter how many levels we have?
source
share