How can I create a nested .map() callback function, so that I may access the elements within a nested array? [duplicate]

1 day ago 2
ARTICLE AD BOX

When using arrow function syntax, putting curly braces around the body allows you to use multiple statements, and you need an explicit return statement to return a value. Your callbacks currently implicitly return undefined; the expression you have between the {…} is a side effect whose value is discarded.

There's syntax sugar for arrow functions that are just a single expression whose return value is the value of that expression: leave off the {…}. So, for example, () => new Foo() is a function that instantiates & returns a Foo, but () => { new Foo() } is a function that instantiates a Foo but doesn't do anything with it, returning undefined instead.

TL;DR I think you want this:

const newArr = arr.map(item => item.map(subItem => subItem + 1));

Or, equivalently, this:

const newArr = arr.map(item => {return item.map(subItem => {return subItem + 1})});
Read Entire Article