0

let arr1=[1,2,3];
let arr2=["a","b","c"];
let arr3=[4,5,6];
let arr4=["d","f","e"];
let res=[];


function first (ar1,ar2,ar3,ar4,res) {

    for (var e1 of ar1){
        let arCache = [];
        arCache.push(e1);
        for (var e2 of ar2){
            arCache.push(e2);
            for (var e3 of ar3 ){
                arCache.push(e3);
                for (var e4 of ar4){
                    arCache.push(e4);
                    res.push(arCache);
                    arCache.pop()
                };arCache.pop();
            };arCache.pop();
        };arCache.pop();
    }; return res;
};1

I want to create a program that takes item from the arrays and combine them. There should be 81 arrays inside the res array with every possible combinations.

when i called this function res array becomes an array with 162 empty arrays where did i make a mistake and how can i fix it?

0 Answers0