The push
method adds whatever you are passing to the array.
In your case, you are adding an array, not the items of that array. That's why you end up with an array inside your array: ["Hello", "World!", ["Hello", "World!"]]
.
What you need to do is pass the items of the array to the push
method. An easy way would be doing the following:
var arr = ["Hello", "World!"]
arr.push(...arr); // Notice the "..."
console.log(arr);
The ...
is for the spread syntax. It indicates that you want to pass the items directly, not the array.
arr.push(...arr);
// It is the same as this
arr.push(arr[0], arr[1]);