hi I want to get the result of this function at once inside the items variable, but when I try to return items I get undefined value , can someone explain why and fix it please?
let arr= [[1,2,3,4],[5,6,7,8],['a','b','c','d']];
let colp = [0,1,3];
function selCol(arr,colp) {
let items = [];
return colp.forEach((element) => {
return arr.map((row) => {
items.push(row[element]);
return items;
});
});
}
forEach()doesn't return anything.map()does. Soreturn colp.forEach((element) => {will always return nothing.