Im trying to get a list of individual tags from the below but i keep getting undefined. What am i doing wrong?
initialState = [{name: "John",tags: ["primary", "secondary"]}, {name: "Mark",tags: ["primary"]}];
let tags = initialState.forEach((el) => {
if (el.tags) {
el.tags.map((tag) => {
return tag;
}, []);
}
})
console.log(tags);
Expected Result
tags = ["primary","secondary","primary"]
Array.prototype.forEachdoesn't return anything. Your innermapis also an useless expression statement, because the return is immediately discarded.