How to duplicate elements in a js array?

arrays, javascript

Solution

I came up with something similar to tymeJV's answer

[2, 3, 1, 4].reduce(function (res, current, index, array) {
    return res.concat([current, current]);
}, []);

Problem

Whats the easiest way (with "native" javascript) to duplicate every element in a javascript array? The order matters. For example: ``` a = [2, 3, 1, 4] // do something with a a // a is now [2, 2, 3, 3, 1, 1, 4, 4] ```

Original source

Related problems