6 ms·
I dig it too, but you could previously flatten an array with concat, and the spread operator. [].concat(...array) Lodash wasn't necessary.
by stevenmays 7y ago
I dig it too, but you could previously flatten an array with concat, and the spread operator. [].concat(...array)
Lodash wasn't necessary.
- ulisesrmzroche 7y agoYeah but that reads so gross. Look at it. It’s actually painful. Much rather have the magic word “flat”
- deleted 7y ago[deleted]
- rglover 7y agoHeh, didn't know that. Thanks for the tip :)
- anchpop 7y agoDon't do that, it won't work for arrays greater than a certain size
- mantap 7y agoNo this is not an alternative, it will fail if the array is too large, as you will exceed the maximum number of arguments a function will accept (which is implementation defined). In general the spread operator should only be used for forwarding arguments not for array operations.
- runarberg 7y ago> In general the spread operator should only be used for forwarding arguments not for array operations. Not quite. You should also use the spread operator when you are spreading an iterable into an array: const unique = [...new Set(arr)];
- masklinn 7y agoSeems like a needlessly unreadable alternative to Array.from unless you're combining multiple iterables or values an iterables e.g. const unique = [...a, ...b]; You might expect that concat would work, but it doesn't handle arbitrary iterables: > [].concat([1][Symbol.iterator](), [2][Symbol.iterator]()) [Array Iterator, Array Iterator] > [...[1][Symbol.iterator](), ...[2][Symbol.iterator]()] [1, 2]
- deleted 7y ago[deleted]