I have an array:
arr = ["a", "b", c"]
I want to double values like
arr = ["a", "b", c", "a", "b", "c"]
(not in particular order).
What's the best way to do it in JavaScript?
Possible solution, using Array#concat
.
var arr = ["a", "b", "c"],
res = arr.concat(arr);
console.log(res);
You could also use ES6 spread syntax with Array.push
:
let arr = ['a', 'b', 'c'];
arr.push(...arr);
console.log(arr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With