I am working with an array of arrays and I need to extract the values from each array. However, when I try to map over the arrays, I end up with just a single array and I'm not sure how to access the individual values.
const arr = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
const arrMap = arr.map((it) => it.map((itm) => itm));
console.log(arrMap);
//I expected to see 1, 2, 3, 4, 5, 6, etc.
//Instead, I got [Array(3), Array(3), Array(3)]
I need to use these values elsewhere in my code, but I'm struggling to figure out how to do so. I tried using a function, but when I tried to return and log the values, I ended up with 'undefined':
const arr = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
const arrMap = (arr) => {
arr.forEach((element) => {
console.log(element);
//The values are logged correctly here
return element;
});
};
console.log(arrMap);
//I ended up with 'undefined'