DEV Community

Discussion on: Modern JavaScript, 10 things you should be using, starting today

Collapse
 
mistval profile image
Randall

Without the spread operator, you can do:

let firstHalf = [ 'one', 'two'];
let secondHalf = ['three', 'four'].concat(firstHalf);
Enter fullscreen mode Exit fullscreen mode

I kind of prefer that way, since it doesn't involve extra syntax. But I'm used to using the spread operator now.

Collapse
 
samselfridge profile image
samselfridge

The fact that this results in an out-of-order array called 'secondHalf' that has ALL the values on it is still annoying...but that's OPs fault not yours @randall

Collapse
 
grad profile image
Alex Grad
[].concat(firstHalf, secondHalf);
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
samselfridge profile image
samselfridge

const fullArray = [].concat(firstHalf, secondHalf);