D
D
Dima2020-04-25 13:34:24
JavaScript
Dima, 2020-04-25 13:34:24

How to beautifully pick up all array elements in an array?

There is an array arrand in it a couple more arrays 0_arrand 1_arr. I need to transfer everything that is in the array arrto a new array arrNewwithout grouping into arrays. How to make it beautiful? So far, only this option has come to mind, but something tells me that it is crooked.

let arrNew = [];
arr.forEach(function(item) {
  item.forEach(function(item) {
    arrNew.push(item);
  });
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-04-25
@qpz

This?

arr = 
console.log ( arr.flat() )

this is a relatively new method, there are "alternatives"
https://developer.mozilla.org/en/docs/Web/JavaScri...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question