It was more an accident to use flat(). Initially i tried to use this:
const concat = (...x) => x a = [1,2,3,4] b = 5 c = concat(a,b) console.log(c) // -> [ [ 1, 2, 3, 4 ], 5 ]
But then you come up with a nested array.
I would prefer to use flat without parameter. flat() ist like flat(1), so it flattens only one level. This let´s you preserve the structure of the initial arrays:
a = [1,[2,3],4] b = [6,[7,8],9] c = [a,5,b].flat() console.log(c) // -> [ 1, [ 2, 3 ], 4, 5, 6, [ 7, 8 ], 9 ]
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
It was more an accident to use flat(). Initially i tried to use this:
But then you come up with a nested array.
I would prefer to use flat without parameter. flat() ist like flat(1), so it flattens only one level. This let´s you preserve the structure of the initial arrays: