I have a dataset of various arrays and objects which is irrelevant to be presented here. The following spr function uses the data to return a multidimensional array defined as arry with the length of six:
function spr() {
let ctgnum = 1;
let selectionOfCtg = [];
// debugger;
for (let i = 0; i < ctg_assoc[ctgnum].length; i++) {
value =
ctg_assoc[ctgnum][i][
Math.floor(Math.random() * Object.values(ctg_assoc[ctgnum][i]).length)
];
selectionOfCtg.push(value);
}
console.log(selectionOfCtg);
let arr = [];
let arry = [];
for (let e of selectionOfCtg) {
len = Object.keys(ctg_ptr[e]).length;
for (let f = 0; f < len; f++) {
arr.push(Object.keys(ctg_ptr[e][f]));
}
arry.push(arr.flat());
arr = [];
}
return arry;
}
arry = spr();
console.log(arry);
When the function is run by itself console.log(arry); returns six arrays as expected and required. However, when the following piece of code is added after the function to find common values within the six arrays, the the first array becomes omitted, hence returning only five arrays:
let result = arry.shift().filter(function (v) {
return arry.every(function (a) {
return a.indexOf(v) !== -1;
});
});
Any idea what might be causing it?