Push an array into the same array JS
Posted: 12 Nov 2020, 12:13
I'm trying to push an array into the same array in javascript, But it doesn't seem to be working; the third element is added continuously.
Here is my code so far:
Expected output: ['Hello', 'World!', ['Hello', 'World!']]
Does somebody know why my code doesn't work, and how to fix it?
Here is my code so far:
Code: Select all
var arr = ['Hello', 'World!']
arr.push(arr);
console.log(arr);
Does somebody know why my code doesn't work, and how to fix it?