0

I have array todos with elements which is also arrays and contain some numbers.

I need to pass through all arrays, how can I do this with .maps() ?

todos = [
[23, 25],
[33, 36],
[55, 66],
]

console.log(todos.map(el => el.map(subEl => subEl)));

7
  • you mean need to combine all child array into one ? like [23,25,33,36,55,66] Commented Mar 27, 2021 at 16:25
  • No, I need to pass through all elements Commented Mar 27, 2021 at 16:25
  • 1
    But you are traversing through all elements... However, map is to be used for mapping. It it is just for passing through all elements, just use for loops (or forEach). Commented Mar 27, 2021 at 16:27
  • If you only want to go through them, then you can use foreach or for loops Commented Mar 27, 2021 at 16:28
  • 1
    @AlexFlow you are nothing did on using map. you are just returning the argument Commented Mar 27, 2021 at 16:37

2 Answers 2

1

Simply: todos.flat().map(x => x)

Sign up to request clarification or add additional context in comments.

Comments

1

you were pretty close but applied the function at the wrong point I believe this is what you're looking for console.log(todos.map(el => el.map(subEl => subEl)));

todos = [
[23, 25],
[33, 36],
[55, 66],
]

todos.map(el => el.map(subEl => console.log(subEl)));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.